1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use crate::convert::{FromMrb, RustBackedValue};
use crate::extn::core::matchdata::MatchData;
use crate::value::Value;
use crate::Mrb;
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum Error {
Fatal,
}
pub fn method(interp: &Mrb, value: &Value) -> Result<Value, Error> {
if let Ok(data) = unsafe { MatchData::try_from_ruby(interp, value) } {
Value::from_mrb(interp, data.borrow().string.as_str())
.freeze()
.map_err(|_| Error::Fatal)
} else {
Err(Error::Fatal)
}
}