Skip to content
Draft
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
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ mime-macro = { path = "./mime-macro", optional = true }
mime-parse = { path = "./mime-parse" }
proc-macro-hack = { version = "0.5", optional = true }
quoted-string = "0.2.2"
serde1 = { version = "1", optional = true, package = "serde" }
serde1 = { version = "1", optional = true, package = "serde", default-features = false }

[features]
macro = ["mime-macro", "proc-macro-hack"]
std = ["serde1?/std"]
# "serde1" optional support

[workspace]
Expand Down
2 changes: 1 addition & 1 deletion benches/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use test::Bencher;

#[bench]
fn bench_fmt(b: &mut Bencher) {
use std::fmt::Write;
use core::fmt::Write;
let mime = ::mime::TEXT_PLAIN_UTF_8;
b.bytes = mime.to_string().as_bytes().len() as u64;
let mut s = String::with_capacity(64);
Expand Down
4 changes: 2 additions & 2 deletions mime-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub fn media_type(tokens: TokenStream) -> TokenStream {
};
let slash = mime.private_subtype_offset();
let plus = match mime.private_suffix_offset() {
Some(i) => quote! { ::std::option::Option::Some(#i) },
None => quote! { ::std::option::Option::None },
Some(i) => quote! { ::core::option::Option::Some(#i) },
None => quote! { ::core::option::Option::None },
};
let params = match mime.private_params_source() {
mime_parse::ParamSource::None => quote! { $crate::private::ParamSource::None },
Expand Down
15 changes: 11 additions & 4 deletions mime-parse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@
//!
//! Nothing to see here. Move along.

use std::error::Error;
use std::{fmt, slice};
#![no_std]

extern crate alloc;

use alloc::borrow::ToOwned;
use alloc::string::String;
use alloc::vec::Vec;
use core::error::Error;
use core::{fmt, slice};

pub mod constants;
mod rfc7231;
Expand Down Expand Up @@ -256,12 +263,12 @@ impl fmt::Display for Mime {

#[inline]
fn as_u16(i: usize) -> u16 {
debug_assert!(i <= std::u16::MAX as usize, "as_u16 overflow");
debug_assert!(i <= core::u16::MAX as usize, "as_u16 overflow");
i as u16
}

#[inline]
fn range(index: (u16, u16)) -> std::ops::Range<usize> {
fn range(index: (u16, u16)) -> core::ops::Range<usize> {
index.0 as usize .. index.1 as usize
}

Expand Down
4 changes: 2 additions & 2 deletions mime-parse/src/rfc7231.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ use crate::{

pub(crate) fn parse(opts: &Parser, src: impl Parse) -> Result<Mime, ParseError> {
let s = src.as_str();
if s.len() > std::u16::MAX as usize {
if s.len() > core::u16::MAX as usize {
return Err(ParseError::TooLong);
}

Expand Down Expand Up @@ -271,7 +271,7 @@ fn params_from_str(s: &str, iter: &mut impl Iterator<Item=(usize, u8)>, mut star
params = ParamSource::Two(sc, a, (name, value));
},
ParamSource::Two(sc, a, b) => {
params = ParamSource::Custom(sc, vec![a, b, (name, value)]);
params = ParamSource::Custom(sc, alloc::vec![a, b, (name, value)]);
},
ParamSource::Custom(_, ref mut vec) => {
vec.push((name, value));
Expand Down
4 changes: 2 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::error::Error;
use std::fmt;
use core::error::Error;
use core::fmt;

use mime_parse::ParseError;

Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![deny(warnings)]
#![deny(missing_docs)]
#![deny(missing_debug_implementations)]
#![no_std]

//! # MediaType and MediaRange
//!
Expand Down Expand Up @@ -80,6 +81,9 @@
//! Err(err) => panic!("that's a bad range: {}", err),
//! }
//! ```

extern crate alloc;

#[cfg(feature = "macro")]
use proc_macro_hack::proc_macro_hack;

Expand Down
1 change: 1 addition & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ impl MediaType {
#[cfg(test)]
mod tests {
use crate::*;
use alloc::string::ToString;

#[test]
fn media_type_atom() {
Expand Down
4 changes: 2 additions & 2 deletions src/range.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::fmt;
use std::str::FromStr;
use core::fmt;
use core::str::FromStr;

use mime_parse::{Mime, Parse};

Expand Down
2 changes: 1 addition & 1 deletion src/serde.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt;
use core::fmt;

use serde1::de::{self, Deserialize, Deserializer};
use serde1::ser::{Serialize, Serializer};
Expand Down
14 changes: 7 additions & 7 deletions src/type_.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::fmt;
use std::str::FromStr;

use core::fmt;
use core::str::FromStr;
use mime_parse::{Mime, Parse};

use crate::{InvalidMime, Value};
Expand Down Expand Up @@ -275,17 +274,18 @@ impl fmt::Display for MediaType {
#[cfg(test)]
mod tests {
use crate::*;
use alloc::string::{String, ToString};

#[test]
fn test_size_of() {
assert!(
std::mem::size_of::<MediaType>() < 100,
core::mem::size_of::<MediaType>() < 100,
"just to be warned if the size grows suddenly"
);

assert_eq!(
std::mem::size_of::<MediaType>(),
std::mem::size_of::<Option<MediaType>>(),
core::mem::size_of::<MediaType>(),
core::mem::size_of::<Option<MediaType>>(),
"option size optimization"
);
}
Expand Down Expand Up @@ -384,7 +384,7 @@ mod tests {

#[test]
fn test_parse_too_long() {
let mut source = vec![b'a'; ::std::u16::MAX as usize];
let mut source = alloc::vec![b'a'; ::core::u16::MAX as usize];
source[5] = b'/';

let mut s = String::from_utf8(source).unwrap();
Expand Down
12 changes: 6 additions & 6 deletions src/value.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::cmp::PartialEq;
use std::fmt;
use std::borrow::Cow;
use core::cmp::PartialEq;
use core::fmt;
use alloc::borrow::Cow;

use mime_parse::Mime;
use quoted_string::{self, ContentChars, AsciiCaseInsensitiveEq};
Expand Down Expand Up @@ -188,9 +188,9 @@ impl<'a> fmt::Display for Value<'a> {

#[cfg(test)]
mod test {
use std::borrow::Cow;
use std::cmp::PartialEq;
use std::fmt::Debug;
use alloc::borrow::Cow;
use core::cmp::PartialEq;
use core::fmt::Debug;

use super::Value;

Expand Down