mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #14274 - stshine:servo-url-index, r=emilio
Implement range index with the Position enum on ServoUrl <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because refactoring <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> r? @emilio <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14274) <!-- Reviewable:end -->
This commit is contained in:
commit
ac6a2681ae
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))]
|
||||
|
@ -152,3 +153,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