fn val_mutable(target: &Target, val: &Value) -> bool {
    use super::TypeKind::*;
    let ty = val.ty(target);

    // ignore zero-sized type
    if !ty.varlen() && ty.size() == 0 {
        return false;
    }

    // only buffer&array type with varlen is mutable, when dir equals to `Out`
    if val.dir() == Dir::Out {
        match ty.kind() {
            BufferString | BufferBlob | BufferFilename => ty.varlen(),
            Array => {
                let ty = ty.checked_as_array();
                let mut ret = true;
                if let Some(r) = ty.range() {
                    ret = *r.start() != *r.end()
                }
                ret
            }
            _ => false,
        }
    } else {
        // Do not mutate const, len, csum
        // For struct. mutate inner fields instead of strutc itself
        !matches!(ty.kind(), Const | Len | Csum | Struct)
    }
}
/// Derive if a value is mutable based on type information and value direction.
Derive if a value is mutable based on type information and value direction.
Derive if a value is mutable based on type information and value direction .
fn val_mutable(target: &Target, val: &Value) -> bool {
    use super::TypeKind::*;
    let ty = val.ty(target);
    // ignore zero-sized type
    if !ty.varlen() && ty.size() == 0 {
        return false;
    }
    // only buffer&array type with varlen is mutable, when dir equals to `Out`
    if val.dir() == Dir::Out {
        match ty.kind() {
            BufferString | BufferBlob | BufferFilename => ty.varlen(),
            Array => {
                let ty = ty.checked_as_array();
                let mut ret = true;
                if let Some(r) = ty.range() {
                    ret = *r.start() != *r.end()
                }
                ret
            }
            _ => false,
        }
    } else {
        // Do not mutate const, len, csum
        // For struct. mutate inner fields instead of strutc itself
        !matches!(ty.kind(), Const | Len | Csum | Struct)
    }
}
fn val_mutable ( target : & Target , val : & Value ) -> bool { use super :: TypeKind :: * ; let ty = val . ty ( target ) ; // ignore zero-sized type if ! ty . varlen ( ) && ty . size ( ) == 0 { return false ; } // only buffer&array type with varlen is mutable, when dir equals to `Out` if val . dir ( ) == Dir :: Out { match ty . kind ( ) { BufferString | BufferBlob | BufferFilename => ty . varlen ( ) , Array => { let ty = ty . checked_as_array ( ) ; let mut ret = true ; if let Some ( r ) = ty . range ( ) { ret = * r . start ( ) != * r . end ( ) } ret } _ => false , } } else { // Do not mutate const, len, csum // For struct. mutate inner fields instead of strutc itself ! matches ! ( ty kind ( ) Const Len Csum Struct ) } }
Derive if a value is mutable based on type information and value direction.
Derive if a value is mutable based on type information and value direction .
target
&Target
val
&Value
target
&Target
val
&Value