update
This commit is contained in:
parent
949340a7f2
commit
b0bae64efc
3 changed files with 10 additions and 10 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -707,7 +707,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "mongod"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"futures",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "mongod"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
edition = "2021"
|
||||
|
||||
[features]
|
||||
|
|
|
@ -10,9 +10,14 @@ use super::{valid::Validate, Model};
|
|||
pub struct Reference(String);
|
||||
|
||||
impl Reference {
|
||||
/// Create a new reference from String
|
||||
pub async fn new_raw(reference: &str) -> Option<Self> {
|
||||
let r = Self(reference.to_string());
|
||||
/// Create a new reference from String without checks
|
||||
pub fn new_raw(reference: &str) -> Self {
|
||||
Self(reference.to_string())
|
||||
}
|
||||
|
||||
/// Create a new reference
|
||||
pub async fn new(model: &str, id: &str) -> Option<Self> {
|
||||
let r = Self(format!("{model}::{id}"));
|
||||
if r.validate().await.is_ok() {
|
||||
Some(r)
|
||||
} else {
|
||||
|
@ -20,11 +25,6 @@ impl Reference {
|
|||
}
|
||||
}
|
||||
|
||||
/// Create a new reference
|
||||
pub async fn new(model: &str, id: &str) -> Option<Self> {
|
||||
Self::new_raw(&format!("{model}::{id}")).await
|
||||
}
|
||||
|
||||
/// Get just the ID of the referenced `Model`
|
||||
pub fn id(&self) -> &str {
|
||||
self.0.split_once("::").unwrap().1
|
||||
|
|
Loading…
Reference in a new issue