Trait ScaffoldingNotes

Source
pub trait ScaffoldingNotes {
    // Required methods
    fn get_note(&self, id: String) -> Option<&Note>;
    fn insert_note(
        &mut self,
        auth: String,
        cont: Vec<u8>,
        acc: Option<String>,
    ) -> String;
    fn modify_note(
        &mut self,
        id: String,
        auth: String,
        cont: Vec<u8>,
        acc: Option<String>,
    );
    fn search_notes(&mut self, search: String) -> Vec<Note>;
    fn remove_note(&mut self, id: String);
}
Expand description

The notes behavior of a Scaffolding object

Required Methods§

Source

fn get_note(&self, id: String) -> Option<&Note>

Retrieves a related Note based on the specific id.

#Example

extern crate scaffolding_core;
  
use scaffolding_core::*;

#[scaffolding_struct("notes")]
#[derive(Clone, Debug, Deserialize, Serialize, Scaffolding, ScaffoldingNotes)]
struct MyEntity {}

impl MyEntity {
    #[scaffolding_fn("notes")]
    fn new() -> Self {
        Self {}
    }
}

let mut entity = MyEntity::new();
let id = entity.insert_note(
    "fsmith".to_string(),
    "This was updated".as_bytes().to_vec(),
    None,
);

assert_eq!(entity.get_note(id).unwrap().content_as_string().unwrap(), "This was updated".to_string());
Source

fn insert_note( &mut self, auth: String, cont: Vec<u8>, acc: Option<String>, ) -> String

Inserts a related Note.

#Example

extern crate scaffolding_core;
  
use scaffolding_core::*;

#[scaffolding_struct("notes")]
#[derive(Clone, Debug, Deserialize, Serialize, Scaffolding, ScaffoldingNotes)]
struct MyEntity {}

impl MyEntity {
    #[scaffolding_fn("notes")]
    fn new() -> Self {
        Self {}
    }
}

let mut entity = MyEntity::new();
let id = entity.insert_note(
    "fsmith".to_string(),
    "This was updated".as_bytes().to_vec(),
    None,
);

assert_eq!(entity.notes.len(), 1);
Source

fn modify_note( &mut self, id: String, auth: String, cont: Vec<u8>, acc: Option<String>, )

Updates a related Note based on the specified id.

#Example

extern crate scaffolding_core;
  
use scaffolding_core::*;

#[scaffolding_struct("notes")]
#[derive(Clone, Debug, Deserialize, Serialize, Scaffolding, ScaffoldingNotes)]
struct MyEntity {}

impl MyEntity {
    #[scaffolding_fn("notes")]
    fn new() -> Self {
        Self {}
    }
}

let mut entity = MyEntity::new();
let id = entity.insert_note(
    "fsmith".to_string(),
    "This was updated".as_bytes().to_vec(),
    None,
);

entity.modify_note(
    id.clone(),
    "fsmith".to_string(),
    "This was updated again".as_bytes().to_vec(),
    Some("private".to_string()),
);
Source

fn search_notes(&mut self, search: String) -> Vec<Note>

Searches the notes for specific string and returns all the notes that were found.

#Example

extern crate scaffolding_core;
  
use scaffolding_core::*;

#[scaffolding_struct("notes")]
#[derive(Clone, Debug, Deserialize, Serialize, Scaffolding, ScaffoldingNotes)]
struct MyEntity {}

impl MyEntity {
    #[scaffolding_fn("notes")]
    fn new() -> Self {
        Self {}
    }
}

let mut entity = MyEntity::new();

let _ = entity.insert_note(
    "fsmith".to_string(),
    "This was updated".as_bytes().to_vec(),
    None,
);
let _ = entity.insert_note(
    "fsmith".to_string(),
    "Something to find here".as_bytes().to_vec(),
    None,
);
let _ = entity.insert_note(
    "fsmith".to_string(),
    "Nonething to find here".as_bytes().to_vec(),
    Some("private".to_string()),
);
  
let search_results = entity.search_notes("thing".to_string());

assert_eq!(search_results.len(), 2);
Source

fn remove_note(&mut self, id: String)

Removes a note for specific id.

#Example

extern crate scaffolding_core;
  
use scaffolding_core::*;

#[scaffolding_struct("notes")]
#[derive(Clone, Debug, Deserialize, Serialize, Scaffolding, ScaffoldingNotes)]
struct MyEntity {}

impl MyEntity {
    #[scaffolding_fn("notes")]
    fn new() -> Self {
        Self {}
    }
}

let mut entity = MyEntity::new();

let _ = entity.insert_note(
    "fsmith".to_string(),
    "This was updated".as_bytes().to_vec(),
    None,
);
let id = entity.insert_note(
    "fsmith".to_string(),
    "Something to find here".as_bytes().to_vec(),
    None,
);
let _ = entity.insert_note(
    "fsmith".to_string(),
    "Nonething to find here".as_bytes().to_vec(),
    Some("private".to_string()),
);
  
entity.remove_note(id);

assert_eq!(entity.notes.len(), 2);

Implementors§