fn build_terminated_if_name(if_name: &str) -> Result<Vec<u8>> {
    // Convert the string slice to bytes, and shadow the variable,
    // since we no longer need the &str version.
    let if_name = if_name.as_bytes();

    // TODO: the 16usize limit of the if_name member from struct Tap is pretty arbitrary.
    // We leave it as is for now, but this should be refactored at some point.
    if if_name.len() > 15 {
        return Err(Error::InvalidIfname);
    }

    let mut terminated_if_name = vec![b'\0'; if_name.len() + 1];
    terminated_if_name[..if_name.len()].copy_from_slice(if_name);

    Ok(terminated_if_name)
}
// Returns a byte vector representing the contents of a null terminated C string which
// contains if_name.
Returns a byte vector representing the contents of a null terminated C string which
contains if_name.
Returns a byte vector representing the contents of a null terminated C string which contains if_name .
fn build_terminated_if_name(if_name: &str) -> Result<Vec<u8>> {
    // Convert the string slice to bytes, and shadow the variable,
    // since we no longer need the &str version.
    let if_name = if_name.as_bytes();
    // TODO: the 16usize limit of the if_name member from struct Tap is pretty arbitrary.
    // We leave it as is for now, but this should be refactored at some point.
    if if_name.len() > 15 {
        return Err(Error::InvalidIfname);
    }
    let mut terminated_if_name = vec![b'\0'; if_name.len() + 1];
    terminated_if_name[..if_name.len()].copy_from_slice(if_name);
    Ok(terminated_if_name)
}
fn build_terminated_if_name ( if_name : & str ) -> Result < Vec < u8 > > { // Convert the string slice to bytes, and shadow the variable, // since we no longer need the &str version. let if_name = if_name . as_bytes ( ) ; // TODO: the 16usize limit of the if_name member from struct Tap is pretty arbitrary. // We leave it as is for now, but this should be refactored at some point. if if_name . len ( ) > 15 { return Err ( Error :: InvalidIfname ) ; } let mut terminated_if_name = vec ! [ b'\0' if_name len ( ) 1 ] ; terminated_if_name [ .. if_name . len ( ) ] . copy_from_slice ( if_name ) ; Ok ( terminated_if_name ) }
Returns a byte vector representing the contents of a null terminated C string which
contains if_name.
Returns a byte vector representing the contents of a null terminated C string which contains if_name .
if_name
&str
if_name
&str