melib/jmap: add Id<_>::empty() contructor

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
pull/279/head
Manos Pitsidianakis 2023-08-28 14:16:11 +03:00
parent 37a787e6bb
commit 6ebdc7f9ae
Signed by: Manos Pitsidianakis
GPG Key ID: 7729C7707F7E09D0
3 changed files with 25 additions and 9 deletions

View File

@ -889,7 +889,7 @@ impl JmapType {
let store = Arc::new(Store {
account_name: Arc::new(s.name.clone()),
account_hash,
account_id: Arc::new(Mutex::new(Id::new())),
account_id: Arc::new(Mutex::new(Id::empty())),
online_status,
event_consumer,
is_subscribed: Arc::new(IsSubscribedFn(is_subscribed)),

View File

@ -75,7 +75,7 @@ pub struct EmailImport {
impl ImportCall {
pub fn new() -> Self {
Self {
account_id: Id::new(),
account_id: Id::empty(),
if_in_state: None,
emails: IndexMap::default(),
}
@ -104,7 +104,7 @@ impl Method<EmailObject> for ImportCall {
impl EmailImport {
pub fn new() -> Self {
Self {
blob_id: Id::new(),
blob_id: Id::empty(),
mailbox_ids: IndexMap::default(),
keywords: IndexMap::default(),
received_at: None,

View File

@ -94,7 +94,7 @@ impl<OBJ> Hash for Id<OBJ> {
impl<OBJ> Default for Id<OBJ> {
fn default() -> Self {
Self::new()
Self::empty()
}
}
@ -107,6 +107,15 @@ impl<OBJ> From<String> for Id<OBJ> {
}
}
impl<OBJ> From<&str> for Id<OBJ> {
fn from(inner: &str) -> Self {
Self {
inner: inner.to_string(),
_ph: PhantomData,
}
}
}
impl<OBJ> std::fmt::Display for Id<OBJ> {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
std::fmt::Display::fmt(&self.inner, fmt)
@ -114,13 +123,20 @@ impl<OBJ> std::fmt::Display for Id<OBJ> {
}
impl<OBJ> Id<OBJ> {
pub fn new() -> Self {
pub fn empty() -> Self {
Self {
inner: String::new(),
_ph: PhantomData,
}
}
pub fn new_uuid_v4() -> Self {
Self {
inner: uuid::Uuid::new_v4().hyphenated().to_string(),
_ph: PhantomData,
}
}
pub fn as_str(&self) -> &str {
self.inner.as_str()
}
@ -303,7 +319,7 @@ where
{
pub fn new() -> Self {
Self {
account_id: Id::new(),
account_id: Id::empty(),
ids: None,
properties: None,
_ph: PhantomData,
@ -478,7 +494,7 @@ where
{
pub fn new() -> Self {
Self {
account_id: Id::new(),
account_id: Id::empty(),
filter: None,
sort: None,
position: 0,
@ -623,7 +639,7 @@ where
{
pub fn new() -> Self {
Self {
account_id: Id::new(),
account_id: Id::empty(),
since_state: State::new(),
max_changes: None,
_ph: PhantomData,
@ -793,7 +809,7 @@ where
{
pub fn new() -> Self {
Self {
account_id: Id::new(),
account_id: Id::empty(),
if_in_state: None,
create: None,
update: None,