Removed unwrap() on getters.
parent
adf6176a8f
commit
a6d1dbeae9
|
@ -68,6 +68,10 @@ impl<O: ChangesObject> ChangesResponse<O> {
|
|||
&self.account_id
|
||||
}
|
||||
|
||||
pub fn unwrap_account_id(self) -> String {
|
||||
self.account_id
|
||||
}
|
||||
|
||||
pub fn old_state(&self) -> &str {
|
||||
&self.old_state
|
||||
}
|
||||
|
@ -76,6 +80,10 @@ impl<O: ChangesObject> ChangesResponse<O> {
|
|||
&self.new_state
|
||||
}
|
||||
|
||||
pub fn unwrap_new_state(self) -> String {
|
||||
self.new_state
|
||||
}
|
||||
|
||||
pub fn has_more_changes(&self) -> bool {
|
||||
self.has_more_changes
|
||||
}
|
||||
|
@ -95,4 +103,8 @@ impl<O: ChangesObject> ChangesResponse<O> {
|
|||
pub fn arguments(&self) -> &O::ChangesResponse {
|
||||
&self.arguments
|
||||
}
|
||||
|
||||
pub fn total_changes(&self) -> usize {
|
||||
self.created.len() + self.updated.len() + self.destroyed.len()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,14 +103,18 @@ impl<O: GetObject> GetRequest<O> {
|
|||
}
|
||||
|
||||
impl<O> GetResponse<O> {
|
||||
pub fn account_id(&self) -> &str {
|
||||
self.account_id.as_ref().unwrap()
|
||||
pub fn account_id(&self) -> Option<&str> {
|
||||
self.account_id.as_deref()
|
||||
}
|
||||
|
||||
pub fn state(&self) -> &str {
|
||||
&self.state
|
||||
}
|
||||
|
||||
pub fn unwrap_state(&mut self) -> String {
|
||||
std::mem::take(&mut self.state)
|
||||
}
|
||||
|
||||
pub fn list(&self) -> &[O] {
|
||||
&self.list
|
||||
}
|
||||
|
|
|
@ -64,8 +64,8 @@ impl<T> Response<T> {
|
|||
self.method_responses.remove(index)
|
||||
}
|
||||
|
||||
pub fn pop_method_response(&mut self) -> T {
|
||||
self.method_responses.pop().unwrap()
|
||||
pub fn pop_method_response(&mut self) -> Option<T> {
|
||||
self.method_responses.pop()
|
||||
}
|
||||
|
||||
pub fn created_ids(&self) -> Option<impl Iterator<Item = (&String, &String)>> {
|
||||
|
|
|
@ -222,16 +222,16 @@ impl<O: SetObject> SetRequest<O> {
|
|||
}
|
||||
|
||||
impl<O: SetObject> SetResponse<O> {
|
||||
pub fn account_id(&self) -> &str {
|
||||
self.account_id.as_ref().unwrap()
|
||||
pub fn account_id(&self) -> Option<&str> {
|
||||
self.account_id.as_deref()
|
||||
}
|
||||
|
||||
pub fn old_state(&self) -> Option<&str> {
|
||||
self.old_state.as_deref()
|
||||
}
|
||||
|
||||
pub fn new_state(&self) -> &str {
|
||||
self.new_state.as_ref().unwrap()
|
||||
pub fn new_state(&self) -> Option<&str> {
|
||||
self.new_state.as_deref()
|
||||
}
|
||||
|
||||
pub fn created(&mut self, id: &str) -> crate::Result<O> {
|
||||
|
|
|
@ -6,48 +6,52 @@ use super::{
|
|||
};
|
||||
|
||||
impl Email<Get> {
|
||||
pub fn id(&self) -> &str {
|
||||
self.id.as_ref().unwrap()
|
||||
pub fn id(&self) -> Option<&str> {
|
||||
self.id.as_deref()
|
||||
}
|
||||
|
||||
pub fn unwrap_id(self) -> String {
|
||||
self.id.unwrap()
|
||||
}
|
||||
|
||||
pub fn blob_id(&self) -> &str {
|
||||
self.blob_id.as_ref().unwrap()
|
||||
pub fn blob_id(&self) -> Option<&str> {
|
||||
self.blob_id.as_deref()
|
||||
}
|
||||
|
||||
pub fn unwrap_blob_id(self) -> String {
|
||||
self.blob_id.unwrap()
|
||||
}
|
||||
|
||||
pub fn thread_id(&self) -> &str {
|
||||
self.thread_id.as_ref().unwrap()
|
||||
pub fn thread_id(&self) -> Option<&str> {
|
||||
self.thread_id.as_deref()
|
||||
}
|
||||
|
||||
pub fn mailbox_ids(&self) -> Vec<&str> {
|
||||
self.mailbox_ids
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.filter(|(_, v)| **v)
|
||||
.map(|(k, _)| k.as_str())
|
||||
.collect()
|
||||
.map(|m| {
|
||||
m.iter()
|
||||
.filter(|(_, v)| **v)
|
||||
.map(|(k, _)| k.as_str())
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
pub fn keywords(&self) -> Vec<&str> {
|
||||
self.keywords
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.filter(|(_, v)| **v)
|
||||
.map(|(k, _)| k.as_str())
|
||||
.collect()
|
||||
.map(|k| {
|
||||
k.iter()
|
||||
.filter(|(_, v)| **v)
|
||||
.map(|(k, _)| k.as_str())
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
pub fn size(&self) -> usize {
|
||||
self.size.unwrap()
|
||||
self.size.unwrap_or(0)
|
||||
}
|
||||
|
||||
pub fn received_at(&self) -> Option<i64> {
|
||||
|
|
|
@ -5,24 +5,24 @@ use crate::{core::get::GetObject, Get, Set};
|
|||
use super::{Address, Delivered, DeliveryStatus, Displayed, EmailSubmission, UndoStatus};
|
||||
|
||||
impl EmailSubmission<Get> {
|
||||
pub fn id(&self) -> &str {
|
||||
self.id.as_ref().unwrap()
|
||||
pub fn id(&self) -> Option<&str> {
|
||||
self.id.as_deref()
|
||||
}
|
||||
|
||||
pub fn unwrap_id(self) -> String {
|
||||
self.id.unwrap()
|
||||
}
|
||||
|
||||
pub fn identity_id(&self) -> &str {
|
||||
self.identity_id.as_ref().unwrap()
|
||||
pub fn identity_id(&self) -> Option<&str> {
|
||||
self.identity_id.as_deref()
|
||||
}
|
||||
|
||||
pub fn email_id(&self) -> &str {
|
||||
self.email_id.as_ref().unwrap()
|
||||
pub fn email_id(&self) -> Option<&str> {
|
||||
self.email_id.as_deref()
|
||||
}
|
||||
|
||||
pub fn thread_id(&self) -> &str {
|
||||
self.thread_id.as_ref().unwrap()
|
||||
pub fn thread_id(&self) -> Option<&str> {
|
||||
self.thread_id.as_deref()
|
||||
}
|
||||
|
||||
pub fn mail_from(&self) -> Option<&Address> {
|
||||
|
@ -33,12 +33,12 @@ impl EmailSubmission<Get> {
|
|||
self.envelope.as_ref().map(|e| e.rcpt_to.as_ref())
|
||||
}
|
||||
|
||||
pub fn send_at(&self) -> i64 {
|
||||
self.send_at.as_ref().unwrap().timestamp()
|
||||
pub fn send_at(&self) -> Option<i64> {
|
||||
self.send_at.as_ref().map(|t| t.timestamp())
|
||||
}
|
||||
|
||||
pub fn undo_status(&self) -> &UndoStatus {
|
||||
self.undo_status.as_ref().unwrap()
|
||||
pub fn undo_status(&self) -> Option<&UndoStatus> {
|
||||
self.undo_status.as_ref()
|
||||
}
|
||||
|
||||
pub fn delivery_status_email(&self, email: &str) -> Option<&DeliveryStatus> {
|
||||
|
|
|
@ -3,8 +3,8 @@ use crate::{core::get::GetObject, email::EmailAddress, Get, Set};
|
|||
use super::Identity;
|
||||
|
||||
impl Identity<Get> {
|
||||
pub fn id(&self) -> &str {
|
||||
self.id.as_ref().unwrap()
|
||||
pub fn id(&self) -> Option<&str> {
|
||||
self.id.as_deref()
|
||||
}
|
||||
|
||||
pub fn unwrap_id(self) -> String {
|
||||
|
@ -15,8 +15,8 @@ impl Identity<Get> {
|
|||
self.name.as_deref()
|
||||
}
|
||||
|
||||
pub fn email(&self) -> &str {
|
||||
self.email.as_ref().unwrap()
|
||||
pub fn email(&self) -> Option<&str> {
|
||||
self.email.as_deref()
|
||||
}
|
||||
|
||||
pub fn reply_to(&self) -> Option<&[EmailAddress]> {
|
||||
|
|
10
src/lib.rs
10
src/lib.rs
|
@ -226,12 +226,12 @@ impl Display for Error {
|
|||
Error::Transport(e) => write!(f, "Transport error: {}", e),
|
||||
Error::Parse(e) => write!(f, "Parse error: {}", e),
|
||||
Error::Internal(e) => write!(f, "Internal error: {}", e),
|
||||
Error::Problem(e) => write!(f, "Problem details: {}", e),
|
||||
Error::Server(e) => write!(f, "Server error: {}", e),
|
||||
Error::Method(e) => write!(f, "Method error: {}", e),
|
||||
Error::Set(e) => write!(f, "Set error: {}", e),
|
||||
Error::Problem(e) => write!(f, "Request failed: {}", e),
|
||||
Error::Server(e) => write!(f, "Server failed: {}", e),
|
||||
Error::Method(e) => write!(f, "Request failed: {}", e),
|
||||
Error::Set(e) => write!(f, "Set failed: {}", e),
|
||||
#[cfg(feature = "websockets")]
|
||||
Error::WebSocket(e) => write!(f, "WebSocket error: {}", e),
|
||||
Error::WebSocket(e) => write!(f, "WebSockets error: {}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@ use crate::{core::get::GetObject, principal::ACL, Get, Set};
|
|||
use super::{Mailbox, MailboxRights, Role};
|
||||
|
||||
impl Mailbox<Get> {
|
||||
pub fn id(&self) -> &str {
|
||||
self.id.as_ref().unwrap()
|
||||
pub fn id(&self) -> Option<&str> {
|
||||
self.id.as_deref()
|
||||
}
|
||||
|
||||
pub fn unwrap_id(self) -> String {
|
||||
|
|
|
@ -116,6 +116,12 @@ pub enum Role {
|
|||
None,
|
||||
}
|
||||
|
||||
impl Default for Role {
|
||||
fn default() -> Self {
|
||||
Role::None
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct MailboxRights {
|
||||
#[serde(rename = "mayReadItems")]
|
||||
|
@ -174,6 +180,18 @@ pub enum Property {
|
|||
ACL,
|
||||
}
|
||||
|
||||
impl Property {
|
||||
pub fn is_count(&self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
Property::TotalEmails
|
||||
| Property::UnreadEmails
|
||||
| Property::TotalThreads
|
||||
| Property::UnreadThreads
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Property {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
|
|
|
@ -5,8 +5,8 @@ use crate::{core::get::GetObject, Get, Set};
|
|||
use super::{Principal, Type, ACL, DKIM};
|
||||
|
||||
impl Principal<Get> {
|
||||
pub fn id(&self) -> &str {
|
||||
self.id.as_ref().unwrap()
|
||||
pub fn id(&self) -> Option<&str> {
|
||||
self.id.as_deref()
|
||||
}
|
||||
|
||||
pub fn unwrap_id(self) -> String {
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
use crate::{core::get::GetObject, Get, TypeState, Set};
|
||||
use crate::{core::get::GetObject, Get, Set, TypeState};
|
||||
|
||||
use super::{Keys, PushSubscription};
|
||||
|
||||
impl PushSubscription<Get> {
|
||||
pub fn id(&self) -> &str {
|
||||
self.id.as_ref().unwrap()
|
||||
pub fn id(&self) -> Option<&str> {
|
||||
self.id.as_deref()
|
||||
}
|
||||
|
||||
pub fn unwrap_id(self) -> String {
|
||||
self.id.unwrap()
|
||||
}
|
||||
|
||||
pub fn device_client_id(&self) -> &str {
|
||||
self.device_client_id.as_ref().unwrap()
|
||||
pub fn device_client_id(&self) -> Option<&str> {
|
||||
self.device_client_id.as_deref()
|
||||
}
|
||||
|
||||
pub fn url(&self) -> &str {
|
||||
self.url.as_ref().unwrap()
|
||||
pub fn url(&self) -> Option<&str> {
|
||||
self.url.as_deref()
|
||||
}
|
||||
|
||||
pub fn keys(&self) -> Option<&Keys> {
|
||||
|
|
|
@ -3,8 +3,8 @@ use crate::{core::get::GetObject, Get, Set};
|
|||
use super::VacationResponse;
|
||||
|
||||
impl VacationResponse<Get> {
|
||||
pub fn id(&self) -> &str {
|
||||
self.id.as_ref().unwrap()
|
||||
pub fn id(&self) -> Option<&str> {
|
||||
self.id.as_deref()
|
||||
}
|
||||
|
||||
pub fn is_enabled(&self) -> bool {
|
||||
|
|
Loading…
Reference in New Issue