mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Implement range index with the Position enum on ServoUrl
This commit is contained in:
parent
22aebdf5d4
commit
0818b44459
6 changed files with 35 additions and 6 deletions
|
@ -19,9 +19,10 @@ extern crate url;
|
|||
|
||||
use std::fmt;
|
||||
use std::net::IpAddr;
|
||||
use std::ops::{Range, RangeFrom, RangeTo, RangeFull, Index};
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
use url::{Url, Origin};
|
||||
use url::{Url, Origin, Position};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf, Serialize, Deserialize))]
|
||||
|
@ -148,3 +149,31 @@ impl fmt::Display for ServoUrl {
|
|||
self.0.fmt(formatter)
|
||||
}
|
||||
}
|
||||
|
||||
impl Index<RangeFull> for ServoUrl {
|
||||
type Output = str;
|
||||
fn index(&self, _: RangeFull) -> &str {
|
||||
&self.0[..]
|
||||
}
|
||||
}
|
||||
|
||||
impl Index<RangeFrom<Position>> for ServoUrl {
|
||||
type Output = str;
|
||||
fn index(&self, range: RangeFrom<Position>) -> &str {
|
||||
&self.0[range]
|
||||
}
|
||||
}
|
||||
|
||||
impl Index<RangeTo<Position>> for ServoUrl {
|
||||
type Output = str;
|
||||
fn index(&self, range: RangeTo<Position>) -> &str {
|
||||
&self.0[range]
|
||||
}
|
||||
}
|
||||
|
||||
impl Index<Range<Position>> for ServoUrl {
|
||||
type Output = str;
|
||||
fn index(&self, range: Range<Position>) -> &str {
|
||||
&self.0[range]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue