Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Added short `README.md` to `assets` folder
* Added quirk for trailing space in STATUS. Thanks, @nbdd0121!
* Increased MSRV to 1.78.
* Made imap-types `no_std` (requires `alloc`), unless `arbitrary` or `tag_generator` are enabled

### Changed

Expand Down
4 changes: 2 additions & 2 deletions imap-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ bounded-static-derive = { version = "0.8.0", default-features = false }
bounded-static = { version = "0.8.0", default-features = false, features = ["alloc"] }
chrono = { version = "0.4", default-features = false }
rand = { version = "0.10", default-features = false, features = ["thread_rng"], optional = true }
serde = { version = "1.0.228", features = ["derive"], optional = true }
thiserror = "2.0.18"
serde = { version = "1.0.228", default-features = false, features = ["alloc", "derive"], optional = true }
thiserror = { version = "2.0.18", default-features = false }

[dev-dependencies]
criterion = { version = "0.7.0", default-features = false }
Expand Down
4 changes: 4 additions & 0 deletions imap-types/src/arbitrary.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#[cfg(not(feature = "arbitrary_simplified"))]
use alloc::boxed::Box;
use alloc::vec::Vec;

use arbitrary::{Arbitrary, Unstructured};
use chrono::{FixedOffset, TimeZone};

Expand Down
8 changes: 6 additions & 2 deletions imap-types/src/auth.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
//! Authentication-related types.

use std::{
use alloc::{
borrow::Cow,
string::{String, ToString},
vec::Vec,
};
use core::{
fmt::{Display, Formatter},
str::FromStr,
};
Expand Down Expand Up @@ -163,7 +167,7 @@ impl<'a> From<Atom<'a>> for AuthMechanism<'a> {
}

impl Display for AuthMechanism<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
f.write_str(self.as_ref())
}
}
Expand Down
2 changes: 2 additions & 0 deletions imap-types/src/body.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Body(structure)-related types.

use alloc::{boxed::Box, vec::Vec};

#[cfg(feature = "arbitrary")]
use arbitrary::Arbitrary;
use bounded_static_derive::ToStatic;
Expand Down
9 changes: 6 additions & 3 deletions imap-types/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
//!
//! See <https://tools.ietf.org/html/rfc3501#section-6>.

use std::borrow::Cow;
use alloc::{borrow::Cow, vec::Vec};
#[cfg(feature = "ext_condstore_qresync")]
use std::num::NonZeroU32;
use core::num::NonZeroU32;
#[cfg(feature = "ext_condstore_qresync")]
use std::num::NonZeroU64;
use core::num::NonZeroU64;

#[cfg(feature = "arbitrary")]
use arbitrary::Arbitrary;
Expand Down Expand Up @@ -1933,6 +1933,9 @@ pub mod error {

#[cfg(test)]
mod tests {
use alloc::{boxed::Box, format, vec};
use std::println;

use chrono::DateTime as ChronoDateTime;

use super::*;
Expand Down
37 changes: 23 additions & 14 deletions imap-types/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,18 @@
//! ```

#[cfg(feature = "tag_generator")]
use std::sync::atomic::{AtomicUsize, Ordering};
use std::{
use alloc::format;
use alloc::{
borrow::Cow,
string::String,
vec,
vec::{IntoIter, Vec},
};
#[cfg(feature = "tag_generator")]
use core::sync::atomic::{AtomicUsize, Ordering};
use core::{
fmt::{Debug, Display, Formatter},
str::from_utf8,
vec::IntoIter,
};

#[cfg(feature = "arbitrary")]
Expand Down Expand Up @@ -113,7 +119,7 @@ pub struct Atom<'a>(pub(crate) Cow<'a, str>);

// We want a slightly more dense `Debug` implementation.
impl Debug for Atom<'_> {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter) -> core::fmt::Result {
write!(f, "Atom({:?})", self.0)
}
}
Expand Down Expand Up @@ -228,7 +234,7 @@ impl AsRef<str> for Atom<'_> {
}

impl Display for Atom<'_> {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter) -> core::fmt::Result {
write!(f, "{}", self.0)
}
}
Expand Down Expand Up @@ -263,7 +269,7 @@ pub struct AtomExt<'a>(pub(crate) Cow<'a, str>);

// We want a slightly more dense `Debug` implementation.
impl Debug for AtomExt<'_> {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter) -> core::fmt::Result {
write!(f, "AtomExt({:?})", self.0)
}
}
Expand Down Expand Up @@ -543,11 +549,11 @@ where

// We want a more readable `Debug` implementation.
impl Debug for Literal<'_> {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter) -> core::fmt::Result {
struct BStr<'a>(&'a Cow<'a, [u8]>);

impl Debug for BStr<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(
f,
"b\"{}\"",
Expand Down Expand Up @@ -763,7 +769,7 @@ pub enum LiteralMode {
pub struct Quoted<'a>(pub(crate) Cow<'a, str>);

impl Debug for Quoted<'_> {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter) -> core::fmt::Result {
write!(f, "Quoted({:?})", self.0)
}
}
Expand Down Expand Up @@ -1061,7 +1067,7 @@ pub struct Tag<'a>(pub(crate) Cow<'a, str>);

// We want a slightly more dense `Debug` implementation.
impl Debug for Tag<'_> {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter) -> core::fmt::Result {
write!(f, "Tag({:?})", self.0)
}
}
Expand Down Expand Up @@ -1233,13 +1239,13 @@ pub struct Text<'a>(pub(crate) Cow<'a, str>);

// We want a slightly more dense `Debug` implementation.
impl Debug for Text<'_> {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter) -> core::fmt::Result {
write!(f, "Text({:?})", self.0)
}
}

impl Display for Text<'_> {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter) -> core::fmt::Result {
write!(f, "{}", self.0.as_ref())
}
}
Expand Down Expand Up @@ -1534,7 +1540,7 @@ impl<T, const N: usize> Debug for VecN<T, N>
where
T: Debug,
{
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter) -> core::fmt::Result {
self.0.fmt(f)?;
match N {
0 => write!(f, "*"),
Expand Down Expand Up @@ -1631,7 +1637,10 @@ impl<T> From<(T, T)> for Vec2<T> {

#[cfg(test)]
mod tests {
use std::str::from_utf8;
use alloc::borrow::ToOwned;
#[cfg(feature = "serde")]
use alloc::string::ToString;
use core::str::from_utf8;
#[cfg(feature = "tag_generator")]
use std::{collections::BTreeSet, thread, time::Duration};

Expand Down
10 changes: 7 additions & 3 deletions imap-types/src/datetime.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Date and time-related types.

use std::fmt::{Debug, Formatter};
use core::fmt::{Debug, Formatter};

use bounded_static::{IntoBoundedStatic, ToBoundedStatic};
use chrono::{Datelike, FixedOffset};
Expand Down Expand Up @@ -64,7 +64,7 @@ impl TryFrom<chrono::DateTime<FixedOffset>> for DateTime {
}

impl Debug for DateTime {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
Debug::fmt(&self.0, f)
}
}
Expand Down Expand Up @@ -134,7 +134,7 @@ impl TryFrom<chrono::NaiveDate> for NaiveDate {
}

impl Debug for NaiveDate {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter) -> core::fmt::Result {
Debug::fmt(&self.0, f)
}
}
Expand Down Expand Up @@ -184,6 +184,10 @@ pub mod error {

#[cfg(test)]
mod tests {
#[cfg(feature = "serde")]
use alloc::string::ToString;
use std::println;

use chrono::{TimeZone, Timelike};

use super::*;
Expand Down
2 changes: 2 additions & 0 deletions imap-types/src/envelope.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Envelope-related types.

use alloc::vec::Vec;

#[cfg(feature = "arbitrary")]
use arbitrary::Arbitrary;
use bounded_static_derive::ToStatic;
Expand Down
4 changes: 2 additions & 2 deletions imap-types/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Error-related types.

use std::fmt::{Display, Formatter};
use core::fmt::{Display, Formatter};

use thiserror::Error;

Expand All @@ -13,7 +13,7 @@ pub struct ValidationError {
}

impl Display for ValidationError {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter) -> core::fmt::Result {
write!(f, "Validation failed: {}", self.kind)
}
}
Expand Down
10 changes: 4 additions & 6 deletions imap-types/src/extensions/binary.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
//! IMAP4 Binary Content Extension

use std::{
borrow::Cow,
fmt::{Debug, Formatter},
};
use alloc::borrow::Cow;
use core::fmt::{Debug, Formatter};

#[cfg(feature = "arbitrary")]
use arbitrary::Arbitrary;
Expand Down Expand Up @@ -41,11 +39,11 @@ pub struct Literal8<'a> {

// We want a more readable `Debug` implementation.
impl Debug for Literal8<'_> {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter) -> core::fmt::Result {
struct BStr<'a>(&'a Cow<'a, [u8]>);

impl Debug for BStr<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(
f,
"b\"{}\"",
Expand Down
4 changes: 2 additions & 2 deletions imap-types/src/extensions/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//! * the [`Command`](crate::command::Command) enum with a new variant [`Command::Compress`](crate::command::Command#variant.Compress), and
//! * the [`Code`](crate::response::Code) enum with a new variant [`Code::CompressionActive`](crate::response::Code#variant.CompressionActive).

use std::fmt::{Display, Formatter};
use core::fmt::{Display, Formatter};

#[cfg(feature = "arbitrary")]
use arbitrary::Arbitrary;
Expand Down Expand Up @@ -43,7 +43,7 @@ pub enum CompressionAlgorithm {
}

impl Display for CompressionAlgorithm {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
f.write_str(match self {
Self::Deflate => "DEFLATE",
})
Expand Down
6 changes: 3 additions & 3 deletions imap-types/src/extensions/condstore_qresync.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt::{Display, Formatter};
use core::fmt::{Display, Formatter};

#[cfg(feature = "arbitrary")]
use arbitrary::Arbitrary;
Expand Down Expand Up @@ -54,7 +54,7 @@ impl<'a> TryFrom<&'a str> for AttributeFlag<'a> {
}

impl Display for AttributeFlag<'_> {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter) -> core::fmt::Result {
match self {
AttributeFlag::Answered => f.write_str("\\\\Answered"),
AttributeFlag::Flagged => f.write_str("\\\\Flagged"),
Expand All @@ -77,7 +77,7 @@ pub enum EntryTypeReq {
}

impl Display for EntryTypeReq {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
match self {
EntryTypeReq::Private => write!(f, "priv"),
EntryTypeReq::Shared => write!(f, "shared"),
Expand Down
4 changes: 2 additions & 2 deletions imap-types/src/extensions/enable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! * the [CommandBody] enum with a new variant [CommandBody::Enable], and
//! * the [Data](crate::response::Data) enum with a new variant [Data::Enabled](crate::response::Data#variant.Enabled).

use std::fmt::{Display, Formatter};
use core::fmt::{Display, Formatter};

use bounded_static_derive::ToStatic;
#[cfg(feature = "serde")]
Expand Down Expand Up @@ -79,7 +79,7 @@ impl<'a> From<Atom<'a>> for CapabilityEnable<'a> {
}

impl Display for CapabilityEnable<'_> {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter) -> core::fmt::Result {
match self {
#[cfg(feature = "ext_condstore_qresync")]
Self::CondStore => write!(f, "CONDSTORE"),
Expand Down
2 changes: 2 additions & 0 deletions imap-types/src/extensions/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
//!
//! - [`Data::Namespace`]

use alloc::vec::Vec;

#[cfg(feature = "arbitrary")]
use arbitrary::Arbitrary;
use bounded_static_derive::ToStatic;
Expand Down
8 changes: 3 additions & 5 deletions imap-types/src/extensions/quota.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@
//! - [`StatusDataItem::Deleted`](crate::status::StatusDataItem::Deleted)
//! - [`StatusDataItem::DeletedStorage`](crate::status::StatusDataItem::DeletedStorage)

use std::{
borrow::Cow,
fmt::{Display, Formatter},
};
use alloc::{borrow::Cow, string::String, vec::Vec};
use core::fmt::{Display, Formatter};

#[cfg(feature = "arbitrary")]
use arbitrary::Arbitrary;
Expand Down Expand Up @@ -207,7 +205,7 @@ impl<'a> From<Atom<'a>> for Resource<'a> {
}

impl Display for Resource<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
f.write_str(match self {
Self::Storage => "STORAGE",
Self::Message => "MESSAGE",
Expand Down
4 changes: 2 additions & 2 deletions imap-types/src/extensions/sort.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt::{Display, Formatter};
use core::fmt::{Display, Formatter};

#[cfg(feature = "arbitrary")]
use arbitrary::{Arbitrary, Unstructured};
Expand Down Expand Up @@ -28,7 +28,7 @@ impl<'a> From<Atom<'a>> for SortAlgorithm<'a> {
}

impl Display for SortAlgorithm<'_> {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter) -> core::fmt::Result {
match self {
SortAlgorithm::Display => f.write_str("DISPLAY"),
SortAlgorithm::Other(other) => f.write_str(other.as_ref()),
Expand Down
Loading
Loading