-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add no_std support #20
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ proc-macro-hack = "0.5.9" | |
|
||
[features] | ||
stable = ["include-flate-codegen/stable"] | ||
std = [] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,21 @@ | ||
#![cfg_attr(not(any(test, feature = "std")), no_std)] | ||
|
||
extern crate alloc; | ||
|
||
#[cfg_attr(feature = "stable", proc_macro_hack::proc_macro_hack)] | ||
pub use include_flate_codegen::deflate_file; | ||
|
||
#[cfg_attr(feature = "stable", proc_macro_hack::proc_macro_hack)] | ||
pub use include_flate_codegen::deflate_utf8_file; | ||
|
||
#[cfg(feature = "std")] | ||
pub type String = ::std::string::String; | ||
|
||
#[cfg(not(feature = "std"))] | ||
pub type String = ::alloc::string::String; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
#[cfg(feature = "std")] | ||
pub type Vec<T> = ::std::vec::Vec<T>; | ||
|
||
#[cfg(not(feature = "std"))] | ||
pub type Vec<T> = ::alloc::vec::Vec<T>; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,10 @@ | |
//! which might be undesirable if the data are too large. | ||
//! An actual installer is still required if the binary involves too many resources that do not need to be kept in RAM all time. | ||
|
||
#![cfg_attr(not(any(test, feature = "std")), no_std)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need a feature gate for this? |
||
|
||
extern crate alloc; | ||
|
||
use libflate::deflate; | ||
|
||
/// The low-level macros used by this crate. | ||
|
@@ -99,7 +103,7 @@ macro_rules! flate { | |
|
||
$crate::lazy_static! { | ||
$(#[$meta])* | ||
$(pub $(($($vis)+))?)? static ref $name: ::std::vec::Vec<u8> = $crate::decode($crate::codegen::deflate_file!($path)); | ||
$(pub $(($($vis)+))?)? static ref $name: $crate::codegen::Vec<u8> = $crate::decode($crate::codegen::deflate_file!($path)); | ||
} | ||
}; | ||
($(#[$meta:meta])* | ||
|
@@ -109,25 +113,25 @@ macro_rules! flate { | |
|
||
$crate::lazy_static! { | ||
$(#[$meta])* | ||
$(pub $(($($vis)+))?)? static ref $name: ::std::string::String = $crate::decode_string($crate::codegen::deflate_utf8_file!($path)); | ||
$(pub $(($($vis)+))?)? static ref $name: $crate::codegen::String = $crate::decode_string($crate::codegen::deflate_utf8_file!($path)); | ||
} | ||
}; | ||
} | ||
|
||
#[doc(hidden)] | ||
pub fn decode(bytes: &[u8]) -> Vec<u8> { | ||
use std::io::{Cursor, Read}; | ||
pub fn decode(bytes: &[u8]) -> codegen::Vec<u8> { | ||
use core2::io::{Cursor, Read}; | ||
|
||
let mut dec = deflate::Decoder::new(Cursor::new(bytes)); | ||
let mut ret = Vec::new(); | ||
let mut ret = codegen::Vec::new(); | ||
dec.read_to_end(&mut ret) | ||
.expect("Compiled DEFLATE buffer was corrupted"); | ||
ret | ||
} | ||
|
||
#[doc(hidden)] | ||
pub fn decode_string(bytes: &[u8]) -> String { | ||
pub fn decode_string(bytes: &[u8]) -> codegen::String { | ||
// We should have checked for utf8 correctness in encode_utf8_file! | ||
String::from_utf8(decode(bytes)) | ||
codegen::String::from_utf8(decode(bytes)) | ||
.expect("flate_str has malformed UTF-8 despite checked at compile time") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please preserve the trailing newlines