fn string_get(s: &str, key: Value) -> Result<Option<String>, VmError> {
    use crate::{FromValue as _, RangeLimits, TypeOf as _};

    match key {
        Value::Range(range) => {
            let range = range.borrow_ref()?;

            let start = match range.start.clone() {
                Some(value) => Some(<usize>::from_value(value)?),
                None => None,
            };

            let end = match range.end.clone() {
                Some(value) => Some(<usize>::from_value(value)?),
                None => None,
            };

            let out = match range.limits {
                RangeLimits::HalfOpen => match (start, end) {
                    (Some(start), Some(end)) => s.get(start..end),
                    (Some(start), None) => s.get(start..),
                    (None, Some(end)) => s.get(..end),
                    (None, None) => s.get(..),
                },
                RangeLimits::Closed => match (start, end) {
                    (Some(start), Some(end)) => s.get(start..=end),
                    (None, Some(end)) => s.get(..=end),
                    _ => return Err(VmError::from(VmErrorKind::UnsupportedRange)),
                },
            };

            Ok(out.map(|out| out.to_owned()))
        }
        index => Err(VmError::from(VmErrorKind::UnsupportedIndexGet {
            target: String::type_info(),
            index: index.type_info()?,
        })),
    }
}
/// Get a specific string index.
Get a specific string index.
Get a specific string index .
fn string_get(s: &str, key: Value) -> Result<Option<String>, VmError> {
    use crate::{FromValue as _, RangeLimits, TypeOf as _};
    match key {
        Value::Range(range) => {
            let range = range.borrow_ref()?;
            let start = match range.start.clone() {
                Some(value) => Some(<usize>::from_value(value)?),
                None => None,
            };
            let end = match range.end.clone() {
                Some(value) => Some(<usize>::from_value(value)?),
                None => None,
            };
            let out = match range.limits {
                RangeLimits::HalfOpen => match (start, end) {
                    (Some(start), Some(end)) => s.get(start..end),
                    (Some(start), None) => s.get(start..),
                    (None, Some(end)) => s.get(..end),
                    (None, None) => s.get(..),
                },
                RangeLimits::Closed => match (start, end) {
                    (Some(start), Some(end)) => s.get(start..=end),
                    (None, Some(end)) => s.get(..=end),
                    _ => return Err(VmError::from(VmErrorKind::UnsupportedRange)),
                },
            };
            Ok(out.map(|out| out.to_owned()))
        }
        index => Err(VmError::from(VmErrorKind::UnsupportedIndexGet {
            target: String::type_info(),
            index: index.type_info()?,
        })),
    }
}
fn string_get ( s : & str , key : Value ) -> Result < Option < String > , VmError > { use crate :: { FromValue as _ , RangeLimits , TypeOf as _ } ; match key { Value :: Range ( range ) => { let range = range . borrow_ref ( ) ? ; let start = match range . start . clone ( ) { Some ( value ) => Some ( < usize > :: from_value ( value ) ? ) , None => None , } ; let end = match range . end . clone ( ) { Some ( value ) => Some ( < usize > :: from_value ( value ) ? ) , None => None , } ; let out = match range . limits { RangeLimits :: HalfOpen => match ( start , end ) { ( Some ( start ) , Some ( end ) ) => s . get ( start .. end ) , ( Some ( start ) , None ) => s . get ( start .. ) , ( None , Some ( end ) ) => s . get ( .. end ) , ( None , None ) => s . get ( .. ) , } , RangeLimits :: Closed => match ( start , end ) { ( Some ( start ) , Some ( end ) ) => s . get ( start ..= end ) , ( None , Some ( end ) ) => s . get ( .. = end ) , _ => return Err ( VmError :: from ( VmErrorKind :: UnsupportedRange ) ) , } , } ; Ok ( out . map ( | out | out . to_owned ( ) ) ) } index => Err ( VmError :: from ( VmErrorKind :: UnsupportedIndexGet { target : String :: type_info ( ) , index : index . type_info ( ) ? , } ) ) , } }
Get a specific string index.
Get a specific string index .
s
&str
key
Value
s
&str
key
Value