Struct green_barrel::models::output_data::OutputData2
source · [−]pub struct OutputData2 {
pub is_valid: bool,
pub final_doc: Option<Document>,
pub final_model_json: Value,
pub fields_name: Vec<String>,
}
Expand description
Output data for check() and save() methods.
Fields
is_valid: bool
final_doc: Option<Document>
final_model_json: Value
fields_name: Vec<String>
Implementations
sourceimpl OutputData2
impl OutputData2
sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Get validation status (boolean).
Example:
let mut model_name = ModelName::new()?;
let output_data = model_name.check()?;
// or
let output_data = model_name.save(None, None)?;
assert!(output_data.is_valid());
sourcepub fn update<T>(&self) -> Result<T, Error>where
T: DeserializeOwned + Sized,
pub fn update<T>(&self) -> Result<T, Error>where
T: DeserializeOwned + Sized,
If there are AutoSlug fields, do an update. Use only for save() method.
Example:
let mut model_name = ModelName::new()?;
let output_data = model_name.save(None, None)?;
if output_data.is_valid() {
model_name = output_data.update()?;
}
sourcepub fn hash(&self) -> String
pub fn hash(&self) -> String
Get/Set Hash-line
Example:
let mut model_name = ModelName::new()?;
let output_data = model_name.check(None)?;
// or
let output_data = model_name.save(None, None)?;
println!("{}", output_data.hash());
println!("{}", output_data.set_hash(hash_line));
pub fn set_hash(&mut self, hash: String)
sourcepub fn obj_id(&self) -> Result<Option<ObjectId>, Box<dyn Error>>
pub fn obj_id(&self) -> Result<Option<ObjectId>, Box<dyn Error>>
Get MongoDB ID from hash-line
Example:
let mut model_name = ModelName::new()?;
let output_data = model_name.check()?;
// or
let output_data = model_name.save(None, None)?;
println!("{:?}", output_data.obj_id()?);
sourcepub fn json(&self) -> Result<String, Box<dyn Error>>
pub fn json(&self) -> Result<String, Box<dyn Error>>
Get Model instance in Json-line format.
Example:
let mut model_name = ModelName::new()?;
let output_data = model_name.check()?;
// or
let output_data = model_name.save(None, None)?;
println!("{}", output_data.json()?);
sourcepub fn created_at(&self) -> Option<&str>
pub fn created_at(&self) -> Option<&str>
Get the creation date of the document.
Example:
let mut model_name = ModelName::new()?;
let output_data = model_name.check()?;
// or
let output_data = model_name.save(None, None)?;
println!("{}", output_data.created_at());
sourcepub fn updated_at(&self) -> Option<&str>
pub fn updated_at(&self) -> Option<&str>
Get the date the document was updated.
Example:
let mut model_name = ModelName::new()?;
let output_data = model_name.check()?;
// or
let output_data = model_name.save(None, None)?;
println!("{}", output_data.updated_at());
sourcepub fn err_msg(&self) -> String
pub fn err_msg(&self) -> String
Get errors message ( for user side ).
Example:
let mut model_name = ModelName::new()?;
let output_data = model_name.check()?;
// or
let output_data = model_name.save(None, None)?;
if output_data.is_valid() {
println!("{}", output_data.err_msg());
}
sourcepub fn print_err(&self)
pub fn print_err(&self)
Printing errors to the console ( for development ).
Example:
let mut model_name = ModelName::new()?;
let output_data = model_name.check()?;
// or
let output_data = model_name.save(None, None)?;
if output_data.is_valid() {
output_data.print_err();
}
sourcepub fn json_for_admin(&self) -> Result<String, Box<dyn Error>>
pub fn json_for_admin(&self) -> Result<String, Box<dyn Error>>
Get field type list in json-line format for admin panel. ( converts a field type map to a list, in the order of the Model fields )
Example:
let mut model_name = ModelName::new()?;
let output_data = model_name.check()?;
// or
let output_data = model_name.save(None, None)?;
println!("{}", output_data.json_for_admin()?);
sourcepub fn get_doc(&self) -> Option<Document>
pub fn get_doc(&self) -> Option<Document>
Get/Set final document
Example:
let mut model_name = ModelName::new()?;
let output_data = model_name.check()?;
// or
let output_data = model_name.save(None, None)?;
println!("{:?}", output_data.get_doc());
println!("{:?}", output_data.set_doc(Some(new_doc)));
pub fn set_doc(&mut self, new_doc: Option<Document>)
sourcepub fn model_json(&self) -> Value
pub fn model_json(&self) -> Value
Get Model instance in serde_json::Value format.
Example:
let mut model_name = ModelName::new()?
;
let output_data = model_name.check()?;
// or
let output_data = model_name.save(None, None)?;
println!("{:?}", output_data.model_json());
Trait Implementations
sourceimpl Converters for OutputData2
impl Converters for OutputData2
sourcefn to_prepared_doc(
doc: Document,
ignore_fields: &[String],
field_type_map: &HashMap<String, String>,
model_name: &str
) -> Result<Document, Box<dyn Error>>
fn to_prepared_doc(
doc: Document,
ignore_fields: &[String],
field_type_map: &HashMap<String, String>,
model_name: &str
) -> Result<Document, Box<dyn Error>>
Get prepared document ( converting data types to model-friendly formats ).
sourcefn one_to_json_val(
db_doc: Document,
ignore_fields: &[String],
field_type_map: &HashMap<String, String>,
model_name: &str,
fields_name: &Vec<String>,
model_json: &mut Value
) -> Result<(), Box<dyn Error>>
fn one_to_json_val(
db_doc: Document,
ignore_fields: &[String],
field_type_map: &HashMap<String, String>,
model_name: &str,
fields_name: &Vec<String>,
model_json: &mut Value
) -> Result<(), Box<dyn Error>>
In the model instance, in the format serde_json::Value,
Update the field type values from the corresponding document from the database. Read more
sourcefn many_to_doc_list(
filter: Option<Document>,
find_options: Option<FindOptions>,
collection: Collection
) -> Result<Vec<Document>, Box<dyn Error>>
fn many_to_doc_list(
filter: Option<Document>,
find_options: Option<FindOptions>,
collection: Collection
) -> Result<Vec<Document>, Box<dyn Error>>
Get prepared documents ( missing fields type ).
Auto Trait Implementations
impl RefUnwindSafe for OutputData2
impl Send for OutputData2
impl Sync for OutputData2
impl Unpin for OutputData2
impl UnwindSafe for OutputData2
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more