artichoke_backend/extn/core/regexp/
enc.rs

1//! Parse encoding parameter to `Regexp#initialize` and `Regexp::compile`.
2
3use super::{Encoding, InvalidEncodingError};
4use crate::extn::prelude::*;
5
6impl TryConvertMut<Value, Encoding> for Artichoke {
7    type Error = InvalidEncodingError;
8
9    fn try_convert_mut(&mut self, value: Value) -> Result<Encoding, Self::Error> {
10        if let Ok(encoding) = value.try_convert_into::<i64>(self) {
11            Encoding::try_from(encoding)
12        } else if let Ok(encoding) = value.try_convert_into_mut::<&[u8]>(self) {
13            Encoding::try_from(encoding)
14        } else {
15            Ok(Encoding::new())
16        }
17    }
18}