Trait scaffolding_core::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§
sourcefn get_note(&self, id: String) -> Option<&Note>
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::*;
use scaffolding_macros::*;
use serde_derive::{Deserialize, Serialize};
use std::collections::BTreeMap;
#[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());
sourcefn insert_note(
&mut self,
auth: String,
cont: Vec<u8>,
acc: Option<String>,
) -> String
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::*;
use scaffolding_macros::*;
use serde_derive::{Deserialize, Serialize};
use std::collections::BTreeMap;
#[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);
sourcefn modify_note(
&mut self,
id: String,
auth: String,
cont: Vec<u8>,
acc: Option<String>,
)
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::*;
use scaffolding_macros::*;
use serde_derive::{Deserialize, Serialize};
use std::collections::BTreeMap;
#[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()),
);
sourcefn search_notes(&mut self, search: String) -> Vec<Note>
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::*;
use scaffolding_macros::*;
use serde_derive::{Deserialize, Serialize};
use std::collections::BTreeMap;
#[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);
sourcefn remove_note(&mut self, id: String)
fn remove_note(&mut self, id: String)
Removes a note for specific id.
#Example
extern crate scaffolding_core;
use scaffolding_core::*;
use scaffolding_macros::*;
use serde_derive::{Deserialize, Serialize};
use std::collections::BTreeMap;
#[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);