From 8eb6e776fece579fa218b9ced3aea1139ab2f5b4 Mon Sep 17 00:00:00 2001 From: Alexey Arbuzov Date: Tue, 30 Apr 2019 16:46:34 +0300 Subject: [PATCH] Add support for no_std --- rust/Cargo.toml | 5 +++++ rust/src/lib.rs | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/rust/Cargo.toml b/rust/Cargo.toml index d98c4bb..beb108d 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -9,3 +9,8 @@ readme = "Readme.markdown" keywords = ["qr-code", "barcode", "encoder", "image"] categories = ["encoding", "multimedia::images"] license = "MIT" + +[features] +default = ["std"] +std = [] +alloc = [] # required for nightly compiler before 1.36.0 diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 4fedaba..71b84b3 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -79,7 +79,22 @@ //! } //! } //! ``` +#![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(feature = "alloc", feature(alloc))] +#![cfg(not(feature = "std"))] +#[macro_use] extern crate alloc; + +#[cfg(not(feature = "std"))] +use alloc::{string::String, vec::Vec}; + +#[cfg(not(feature = "std"))] +mod std { + pub use core::i32; + pub use core::cmp; + pub use core::fmt; + pub use alloc::collections; +} /*---- QrCode functionality ----*/ @@ -1274,6 +1289,7 @@ impl BitBuffer { #[derive(Debug, Clone)] pub struct DataTooLong(String); +#[cfg(feature = "std")] impl std::error::Error for DataTooLong { fn description(&self) -> &str { &self.0