mirror of
https://github.com/openharmony/third_party_rust_shlex.git
synced 2026-07-01 21:34:03 -04:00
Add std feature, allow crate to work in #![no_std] mode
Disabling the `std` feature (by setting `default-features = false` for this crate in the Cargo.toml of something requiring it) will enable the crate to work without the standard library, assuming the presence of the `alloc` crate and a working global allocator. We've explicitly imported the individual `alloc` items required by this crate, rather than using `#![feature(alloc_prelude)]` as `alloc_prelude` requires Rust nightly, and doing it that way would be a breaking change to the MSRV. Tested with Cargo/rustc 1.53.0
This commit is contained in:
@@ -12,3 +12,7 @@ categories = [
|
||||
"command-line-interface",
|
||||
"parser-implementations"
|
||||
]
|
||||
|
||||
[features]
|
||||
std = []
|
||||
default = ["std"]
|
||||
|
||||
@@ -11,6 +11,10 @@ specially, which I believe is more compliant.
|
||||
The algorithms in this crate are oblivious to UTF-8 high bytes, so they iterate
|
||||
over the bytes directly as a micro-optimization.
|
||||
|
||||
Disabling the `std` feature (which is enabled by default) will allow the crate
|
||||
to work in `no_std` environments, where a the `alloc` crate, and a global
|
||||
allocator, are available.
|
||||
|
||||
# LICENSE
|
||||
|
||||
The source code in this repository is Licensed under either of
|
||||
|
||||
+14
-2
@@ -14,13 +14,25 @@
|
||||
//!
|
||||
//! The algorithms in this crate are oblivious to UTF-8 high bytes, so they iterate over the bytes
|
||||
//! directly as a micro-optimization.
|
||||
//!
|
||||
//! Disabling the `std` feature (which is enabled by default) will allow the crate to work in
|
||||
//! `no_std` environments, where a the `alloc` crate, and a global allocator, are available.
|
||||
|
||||
use std::borrow::Cow;
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
extern crate alloc;
|
||||
use alloc::vec::Vec;
|
||||
use alloc::borrow::Cow;
|
||||
use alloc::string::String;
|
||||
#[cfg(test)]
|
||||
use alloc::vec;
|
||||
#[cfg(test)]
|
||||
use alloc::borrow::ToOwned;
|
||||
|
||||
/// An iterator that takes an input string and splits it into the words using the same syntax as
|
||||
/// the POSIX shell.
|
||||
pub struct Shlex<'a> {
|
||||
in_iter: std::str::Bytes<'a>,
|
||||
in_iter: core::str::Bytes<'a>,
|
||||
/// The number of newlines read so far, plus one.
|
||||
pub line_no: usize,
|
||||
/// An input string is erroneous if it ends while inside a quotation or right after an
|
||||
|
||||
Reference in New Issue
Block a user