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]]
|
[[package]]
|
||||||
name = "mongod"
|
name = "mongod"
|
||||||
version = "0.2.1"
|
version = "0.2.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"futures",
|
"futures",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "mongod"
|
name = "mongod"
|
||||||
version = "0.2.1"
|
version = "0.2.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|
|
@ -10,9 +10,14 @@ use super::{valid::Validate, Model};
|
||||||
pub struct Reference(String);
|
pub struct Reference(String);
|
||||||
|
|
||||||
impl Reference {
|
impl Reference {
|
||||||
/// Create a new reference from String
|
/// Create a new reference from String without checks
|
||||||
pub async fn new_raw(reference: &str) -> Option<Self> {
|
pub fn new_raw(reference: &str) -> Self {
|
||||||
let r = Self(reference.to_string());
|
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() {
|
if r.validate().await.is_ok() {
|
||||||
Some(r)
|
Some(r)
|
||||||
} else {
|
} 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`
|
/// Get just the ID of the referenced `Model`
|
||||||
pub fn id(&self) -> &str {
|
pub fn id(&self) -> &str {
|
||||||
self.0.split_once("::").unwrap().1
|
self.0.split_once("::").unwrap().1
|
||||||
|
|
Loading…
Reference in a new issue