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