Skip to content

Commit 3675d2e

Browse files
committed
feat!: Support no_std+alloc
1 parent 464837b commit 3675d2e

File tree

11 files changed

+41
-11
lines changed

11 files changed

+41
-11
lines changed

src/builder.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ pub mod affordance;
206206
pub mod data_schema;
207207
mod human_readable_info;
208208

209-
use std::{fmt, marker::PhantomData, ops::Not};
209+
use alloc::{borrow::ToOwned, fmt, string::*, vec, vec::Vec};
210+
use core::{marker::PhantomData, ops::Not};
210211

211212
use hashbrown::{hash_map::Entry, HashMap};
212213
use oxilangtag::LanguageTag;
@@ -996,7 +997,7 @@ impl<Other: ExtendableThing, Status> ThingBuilder<Other, Status> {
996997
if security_definitions.contains_key(security) {
997998
Ok(())
998999
} else {
999-
Err(Error::UndefinedSecurity(std::mem::take(security)))
1000+
Err(Error::UndefinedSecurity(core::mem::take(security)))
10001001
}
10011002
})
10021003
})
@@ -1847,7 +1848,7 @@ impl<T> LinkBuilder<T> {
18471848

18481849
/// The builder elements related to security
18491850
pub mod security {
1850-
use std::borrow::Cow;
1851+
use alloc::{borrow::Cow, string::*, vec::Vec};
18511852

18521853
use serde_json::Value;
18531854

@@ -3026,7 +3027,7 @@ impl TryFrom<UncheckedLink> for Link {
30263027

30273028
#[cfg(test)]
30283029
mod tests {
3029-
use std::borrow::Cow;
3030+
use alloc::borrow::Cow;
30303031

30313032
use serde::{Deserialize, Serialize};
30323033
use serde_json::json;

src/builder/affordance.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
//!
66
//! See the examples related to the specific affordance bulders for more information.
77
8-
use std::ops::Not;
8+
use alloc::{string::String, vec::Vec};
9+
use core::ops::Not;
910

1011
use hashbrown::HashMap;
1112
use serde_json::Value;
@@ -2788,6 +2789,8 @@ where
27882789

27892790
#[cfg(test)]
27902791
mod test {
2792+
use alloc::{borrow::ToOwned, boxed::Box, string::*, vec};
2793+
27912794
use serde::{Deserialize, Serialize};
27922795
use serde_json::json;
27932796

src/builder/data_schema.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
//! [`finish_extend`]: DataSchemaBuilder::finish_extend
4040
//! [`read_only`]: crate::thing::DataSchema::read_only
4141
//! [`write_only`]: crate::thing::DataSchema::write_only
42-
use std::{cmp::Ordering, marker::PhantomData, num::NonZeroU64, ops::Not};
42+
use alloc::{boxed::Box, string::String, vec::Vec};
43+
use core::{cmp::Ordering, marker::PhantomData, num::NonZeroU64, ops::Not};
4344

4445
use hashbrown::HashMap;
4546

@@ -2059,7 +2060,7 @@ macro_rules! impl_inner_delegate_schema_builder_like_integer {
20592060
}
20602061

20612062
#[inline]
2062-
fn multiple_of(mut self, value: std::num::NonZeroU64) -> Self {
2063+
fn multiple_of(mut self, value: core::num::NonZeroU64) -> Self {
20632064
self.$inner = self.$inner.multiple_of(value);
20642065
self
20652066
}
@@ -4050,6 +4051,7 @@ impl<DS, AS, OS> TryFrom<UncheckedObjectSchema<DS, AS, OS>> for ObjectSchema<DS,
40504051

40514052
#[cfg(test)]
40524053
mod tests {
4054+
use alloc::{boxed::Box, string::*, vec};
40534055
use serde::{Deserialize, Serialize};
40544056
use serde_json::json;
40554057

src/builder/human_readable_info.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
//! This module contains the logic shared across multiple builders for the respective
44
//! Thing Description Vocabulary definitions.
55
6+
use alloc::{string::*, vec::Vec};
7+
68
use super::MultiLanguageBuilder;
79

810
/// Human readable informations and semantic tagging

src/flat_map_serialize.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use alloc::vec::Vec;
12
use core::fmt::{self, Display};
23
use serde::ser::{self, Impossible, Serialize, SerializeMap, Serializer};
34

@@ -49,6 +50,7 @@ impl Display for Unsupported {
4950

5051
#[cfg(any(feature = "std", feature = "alloc"))]
5152
mod content {
53+
use alloc::{borrow::ToOwned, boxed::Box, string::String, vec::Vec};
5254
use core::marker::PhantomData;
5355
use serde::ser::{self, Serialize, Serializer};
5456

src/hlist.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ impl From<Nil> for () {
234234

235235
#[cfg(test)]
236236
mod tests {
237+
use alloc::string::*;
237238
use serde_json::{json, Value};
238239

239240
use super::*;

src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@
7373
//!
7474
//! See [`builder`] module for more examples.
7575
76+
#![no_std]
77+
78+
#[cfg(feature = "std")]
79+
extern crate std;
80+
81+
extern crate alloc;
82+
7683
pub mod builder;
7784
pub mod extend;
7885
pub mod hlist;

src/protocol/coap.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ impl ExtendableThing for CoapProtocol {
9595

9696
#[cfg(test)]
9797
mod test {
98+
use alloc::vec;
99+
98100
use super::{BlockSize, CoapProtocol};
99101
use crate::thing::{ExpectedResponse, Form};
100102
fn deserialize_form(s: &str, r: Form<CoapProtocol>) {

src/protocol/http.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! HTTP Binding Template
22
3+
use alloc::{string::String, vec::Vec};
4+
35
use crate::extend::ExtendableThing;
46
use serde::{Deserialize, Serialize};
57
use serde_with::{serde_as, skip_serializing_none};
@@ -65,6 +67,8 @@ impl ExtendableThing for HttpProtocol {
6567

6668
#[cfg(test)]
6769
mod test {
70+
use alloc::vec;
71+
6872
use super::HttpProtocol;
6973
use crate::thing::{ExpectedResponse, Form};
7074

src/protocol/mqtt.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! MQTT Binding Template
22
3+
use alloc::{string::String, vec::Vec};
4+
35
use crate::extend::ExtendableThing;
46
use serde::{Deserialize, Serialize};
57
use serde_with::{serde_as, skip_serializing_none, OneOrMany};
@@ -33,7 +35,7 @@ pub enum QoS {
3335
pub struct Form {
3436
#[serde(
3537
rename = "mqv:retain",
36-
skip_serializing_if = "std::ops::Not::not",
38+
skip_serializing_if = "core::ops::Not::not",
3739
default
3840
)]
3941
pub retain: bool,
@@ -66,6 +68,8 @@ impl ExtendableThing for MqttProtocol {
6668

6769
#[cfg(test)]
6870
mod test {
71+
use alloc::vec;
72+
6973
use super::MqttProtocol;
7074
use crate::thing::Form;
7175
use crate::thing::{DefaultedFormOperations::Custom, FormOperation::*};

0 commit comments

Comments
 (0)