Skip to content

Commit

Permalink
Move ?Sized bounds out of generic parameter lists
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Mar 28, 2020
1 parent 2a8ed51 commit 8db3954
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 208 deletions.
24 changes: 12 additions & 12 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ 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]
pub fn get<Q: ?Sized>(&self, key: &Q) -> Option<&Value>
pub fn get<Q>(&self, key: &Q) -> Option<&Value>
where
String: Borrow<Q>,
Q: Ord + Eq + Hash,
Q: ?Sized + Ord + Eq + Hash,
{
self.map.get(key)
}
Expand All @@ -78,10 +78,10 @@ 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]
pub fn contains_key<Q: ?Sized>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
where
String: Borrow<Q>,
Q: Ord + Eq + Hash,
Q: ?Sized + Ord + Eq + Hash,
{
self.map.contains_key(key)
}
Expand All @@ -91,10 +91,10 @@ 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]
pub fn get_mut<Q: ?Sized>(&mut self, key: &Q) -> Option<&mut Value>
pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut Value>
where
String: Borrow<Q>,
Q: Ord + Eq + Hash,
Q: ?Sized + Ord + Eq + Hash,
{
self.map.get_mut(key)
}
Expand All @@ -116,10 +116,10 @@ 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]
pub fn remove<Q: ?Sized>(&mut self, key: &Q) -> Option<Value>
pub fn remove<Q>(&mut self, key: &Q) -> Option<Value>
where
String: Borrow<Q>,
Q: Ord + Eq + Hash,
Q: ?Sized + Ord + Eq + Hash,
{
#[cfg(feature = "preserve_order")]
return self.map.swap_remove(key);
Expand Down Expand Up @@ -249,10 +249,10 @@ impl PartialEq for Map<String, Value> {
/// }
/// # ;
/// ```
impl<'a, Q: ?Sized> ops::Index<&'a Q> for Map<String, Value>
impl<'a, Q> ops::Index<&'a Q> for Map<String, Value>
where
String: Borrow<Q>,
Q: Ord + Eq + Hash,
Q: ?Sized + Ord + Eq + Hash,
{
type Output = Value;

Expand All @@ -272,10 +272,10 @@ where
/// #
/// map["key"] = json!("value");
/// ```
impl<'a, Q: ?Sized> ops::IndexMut<&'a Q> for Map<String, Value>
impl<'a, Q> ops::IndexMut<&'a Q> for Map<String, Value>
where
String: Borrow<Q>,
Q: Ord + Eq + Hash,
Q: ?Sized + Ord + Eq + Hash,
{
fn index_mut(&mut self, index: &Q) -> &mut Value {
self.map.get_mut(index).expect("no entry found for key")
Expand Down
29 changes: 22 additions & 7 deletions src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,18 @@ pub struct Position {
pub column: usize,
}

pub enum Reference<'b, 'c, T: ?Sized + 'static> {
pub enum Reference<'b, 'c, T>
where
T: ?Sized + 'static,
{
Borrowed(&'b T),
Copied(&'c T),
}

impl<'b, 'c, T: ?Sized + 'static> Deref for Reference<'b, 'c, T> {
impl<'b, 'c, T> Deref for Reference<'b, 'c, T>
where
T: ?Sized + 'static,
{
type Target = T;

fn deref(&self) -> &Self::Target {
Expand Down Expand Up @@ -416,14 +422,14 @@ impl<'a> SliceRead<'a> {
/// The big optimization here over IoRead is that if the string contains no
/// backslash escape sequences, the returned &str is a slice of the raw JSON
/// data so we avoid copying into the scratch space.
fn parse_str_bytes<'s, T: ?Sized, F>(
fn parse_str_bytes<'s, T, F>(
&'s mut self,
scratch: &'s mut Vec<u8>,
validate: bool,
result: F,
) -> Result<Reference<'a, 's, T>>
where
T: 's,
T: ?Sized + 's,
F: for<'f> FnOnce(&'s Self, &'f [u8]) -> Result<&'f T>,
{
// Index of the first byte not yet copied into the scratch space.
Expand Down Expand Up @@ -707,14 +713,20 @@ static ESCAPE: [bool; 256] = {
]
};

fn next_or_eof<'de, R: ?Sized + Read<'de>>(read: &mut R) -> Result<u8> {
fn next_or_eof<'de, R>(read: &mut R) -> Result<u8>
where
R: ?Sized + Read<'de>,
{
match tri!(read.next()) {
Some(b) => Ok(b),
None => error(read, ErrorCode::EofWhileParsingString),
}
}

fn error<'de, R: ?Sized + Read<'de>, T>(read: &R, reason: ErrorCode) -> Result<T> {
fn error<'de, R, T>(read: &R, reason: ErrorCode) -> Result<T>
where
R: ?Sized + Read<'de>,
{
let position = read.position();
Err(Error::syntax(reason, position.line, position.column))
}
Expand Down Expand Up @@ -789,7 +801,10 @@ fn parse_escape<'de, R: Read<'de>>(read: &mut R, scratch: &mut Vec<u8>) -> Resul

/// Parses a JSON escape sequence and discards the value. Assumes the previous
/// byte read was a backslash.
fn ignore_escape<'de, R: ?Sized + Read<'de>>(read: &mut R) -> Result<()> {
fn ignore_escape<'de, R>(read: &mut R) -> Result<()>
where
R: ?Sized + Read<'de>,
{
let ch = tri!(next_or_eof(read));

match ch {
Expand Down
Loading

0 comments on commit 8db3954

Please sign in to comment.