mirror of
https://github.com/serde-rs/json.git
synced 2025-10-02 07:21:29 +00:00
Merge pull request #1062 from osiewicz/remove_build_rs
Simplify/remove build.rs following the bump to 2021 edition
This commit is contained in:
commit
2c22077f0e
37
build.rs
37
build.rs
@ -1,6 +1,4 @@
|
||||
use std::env;
|
||||
use std::process::Command;
|
||||
use std::str::{self, FromStr};
|
||||
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-changed=build.rs");
|
||||
@ -16,39 +14,4 @@ fn main() {
|
||||
println!("cargo:rustc-cfg=limb_width_32");
|
||||
}
|
||||
}
|
||||
|
||||
let minor = match rustc_minor_version() {
|
||||
Some(minor) => minor,
|
||||
None => return,
|
||||
};
|
||||
|
||||
// BTreeMap::get_key_value
|
||||
// https://blog.rust-lang.org/2019/12/19/Rust-1.40.0.html#additions-to-the-standard-library
|
||||
if minor < 40 {
|
||||
println!("cargo:rustc-cfg=no_btreemap_get_key_value");
|
||||
}
|
||||
|
||||
// BTreeMap::remove_entry
|
||||
// https://blog.rust-lang.org/2020/07/16/Rust-1.45.0.html#library-changes
|
||||
if minor < 45 {
|
||||
println!("cargo:rustc-cfg=no_btreemap_remove_entry");
|
||||
}
|
||||
|
||||
// BTreeMap::retain
|
||||
// https://blog.rust-lang.org/2021/06/17/Rust-1.53.0.html#stabilized-apis
|
||||
if minor < 53 {
|
||||
println!("cargo:rustc-cfg=no_btreemap_retain");
|
||||
}
|
||||
}
|
||||
|
||||
fn rustc_minor_version() -> Option<u32> {
|
||||
let rustc = env::var_os("RUSTC")?;
|
||||
let output = Command::new(rustc).arg("--version").output().ok()?;
|
||||
let version = str::from_utf8(&output.stdout).ok()?;
|
||||
let mut pieces = version.split('.');
|
||||
if pieces.next() != Some("rustc 1") {
|
||||
return None;
|
||||
}
|
||||
let next = pieces.next()?;
|
||||
u32::from_str(next).ok()
|
||||
}
|
||||
|
41
src/map.rs
41
src/map.rs
@ -106,7 +106,6 @@ impl Map<String, Value> {
|
||||
/// The key may be any borrowed form of the map's key type, but the ordering
|
||||
/// on the borrowed form *must* match the ordering on the key type.
|
||||
#[inline]
|
||||
#[cfg(any(feature = "preserve_order", not(no_btreemap_get_key_value)))]
|
||||
pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&String, &Value)>
|
||||
where
|
||||
String: Borrow<Q>,
|
||||
@ -153,44 +152,7 @@ impl Map<String, Value> {
|
||||
String: Borrow<Q>,
|
||||
Q: ?Sized + Ord + Eq + Hash,
|
||||
{
|
||||
#[cfg(any(feature = "preserve_order", not(no_btreemap_remove_entry)))]
|
||||
return self.map.remove_entry(key);
|
||||
#[cfg(all(
|
||||
not(feature = "preserve_order"),
|
||||
no_btreemap_remove_entry,
|
||||
not(no_btreemap_get_key_value),
|
||||
))]
|
||||
{
|
||||
let (key, _value) = self.map.get_key_value(key)?;
|
||||
let key = key.clone();
|
||||
let value = self.map.remove::<String>(&key)?;
|
||||
Some((key, value))
|
||||
}
|
||||
#[cfg(all(
|
||||
not(feature = "preserve_order"),
|
||||
no_btreemap_remove_entry,
|
||||
no_btreemap_get_key_value,
|
||||
))]
|
||||
{
|
||||
use core::ops::{Bound, RangeBounds};
|
||||
|
||||
struct Key<'a, Q: ?Sized>(&'a Q);
|
||||
|
||||
impl<'a, Q: ?Sized> RangeBounds<Q> for Key<'a, Q> {
|
||||
fn start_bound(&self) -> Bound<&Q> {
|
||||
Bound::Included(self.0)
|
||||
}
|
||||
fn end_bound(&self) -> Bound<&Q> {
|
||||
Bound::Included(self.0)
|
||||
}
|
||||
}
|
||||
|
||||
let mut range = self.map.range(Key(key));
|
||||
let (key, _value) = range.next()?;
|
||||
let key = key.clone();
|
||||
let value = self.map.remove::<String>(&key)?;
|
||||
Some((key, value))
|
||||
}
|
||||
self.map.remove_entry(key)
|
||||
}
|
||||
|
||||
/// Moves all elements from other into self, leaving other empty.
|
||||
@ -276,7 +238,6 @@ impl Map<String, Value> {
|
||||
///
|
||||
/// In other words, remove all pairs `(k, v)` such that `f(&k, &mut v)`
|
||||
/// returns `false`.
|
||||
#[cfg(not(no_btreemap_retain))]
|
||||
#[inline]
|
||||
pub fn retain<F>(&mut self, f: F)
|
||||
where
|
||||
|
@ -35,7 +35,6 @@ fn test_append() {
|
||||
assert!(val.is_empty());
|
||||
}
|
||||
|
||||
#[cfg(not(no_btreemap_retain))]
|
||||
#[test]
|
||||
fn test_retain() {
|
||||
let mut v: Value = from_str(r#"{"b":null,"a":null,"c":null}"#).unwrap();
|
||||
|
Loading…
x
Reference in New Issue
Block a user