// Create the Tip and the data file associated with this tip
Create the Tip and the data file associated with this tip
Create the Tip and the data file associated with this tip
fn create(contents: String) -> crate::tip::Tip {
    // Split the contents based on separator string, create a
    // create metadata struct and write down the data section to a file
    // before creating the Tip.
    let byte_index = match contents.find(TIP.separator) {
        Some(byte_index) => byte_index,
        None    => {
            panic!("Unable to find split pattern!")
        },
    };
    let (_metadata, _data) = contents.split_at(byte_index);
    let mut __data = _data.to_string();
    __data.replace_range(..TIP.separator.len(), "");
    __data.remove(0); // remove newline left from above
    // First deserialize the Metadata from String, then add the datetime to the
    // created field in Metadata.
    let mut md: crate::metadata::Metadata = match serde_yaml::from_str(&_metadata) {
        Ok(md) => md,
        Err(err) => {
            panic!("Error deserialize metadata {}\n{}",
                   &_metadata, err)
        },
    };
    md.created = Some(chrono::offset::Local::now());
    // Generate a new uudi for this Tip's data.
    let uuid = uuid::Uuid::new_v4();
    crate::helpers::write_to_file(
        &format!("{}/{}", &CONFIG.data, uuid),
        &__data);
    crate::tip::Tip { metadata: md, data: uuid }
}
fn create ( contents : String ) -> crate :: tip :: Tip { // Split the contents based on separator string, create a // create metadata struct and write down the data section to a file // before creating the Tip. let byte_index = match contents . find ( TIP . separator ) { Some ( byte_index ) => byte_index , None => { panic ! ( " " ) } , } ; let ( _metadata , _data ) = contents . split_at ( byte_index ) ; let mut __data = _data . to_string ( ) ; __data . replace_range ( .. TIP . separator . len ( ) , " " ) ; __data . remove ( 0 ) ; // remove newline left from above // First deserialize the Metadata from String, then add the datetime to the // created field in Metadata. let mut md : crate :: metadata :: Metadata = match serde_yaml :: from_str ( & _metadata ) { Ok ( md ) => md , Err ( err ) => { panic ! ( " \n " metadata err ) } , } ; md . created = Some ( chrono :: offset :: Local :: now ( ) ) ; // Generate a new uudi for this Tip's data. let uuid = uuid :: Uuid :: new_v4 ( ) ; crate :: helpers :: write_to_file ( & format ! ( " " CONFIG data uuid ) , & __data ) ; crate :: tip :: Tip { metadata : md , data : uuid } }
Create the Tip and the data file associated with this tip
Create the Tip and the data file associated with this tip
contents
String