pub fn either<T, U, V>(f_left: &fn(&T) -> V,
f_right: &fn(&U) -> V, value: &Either<T, U>) -> V {
match *value {
- Left(ref l) => f_left(l),
- Right(ref r) => f_right(r)
+ Left(ref l) => f_left(l),
+ Right(ref r) => f_right(r)
}
}
let mut rights: ~[U] = ~[];
do vec::consume(eithers) |_i, elt| {
match elt {
- Left(l) => lefts.push(l),
- Right(r) => rights.push(r)
+ Left(l) => lefts.push(l),
+ Right(r) => rights.push(r)
}
}
return (lefts, rights);
#[inline(always)]
pub fn flip<T, U>(eith: Either<T, U>) -> Either<U, T> {
match eith {
- Right(r) => Left(r),
- Left(l) => Right(l)
+ Right(r) => Left(r),
+ Left(l) => Right(l)
}
}
#[inline(always)]
pub fn to_result<T, U>(eith: Either<T, U>) -> Result<U, T> {
match eith {
- Right(r) => result::Ok(r),
- Left(l) => result::Err(l)
+ Right(r) => result::Ok(r),
+ Left(l) => result::Err(l)
}
}
/// Checks whether the given value is a left
#[inline(always)]
pub fn is_left<T, U>(eith: &Either<T, U>) -> bool {
- match *eith { Left(_) => true, _ => false }
+ match *eith {
+ Left(_) => true,
+ _ => false
+ }
}
/// Checks whether the given value is a right
#[inline(always)]
pub fn is_right<T, U>(eith: &Either<T, U>) -> bool {
- match *eith { Right(_) => true, _ => false }
+ match *eith {
+ Right(_) => true,
+ _ => false
+ }
}
/// Retrieves the value in the left branch. Fails if the either is Right.
components.push(s.to_owned())
}
let is_absolute = (s.len() != 0 && s[0] == '/' as u8);
- return PosixPath { is_absolute: is_absolute,
- components: components }
+ PosixPath {
+ is_absolute: is_absolute,
+ components: components,
+ }
}
fn dirname(&self) -> ~str {
fn filename(&self) -> Option<~str> {
match self.components.len() {
- 0 => None,
- n => Some(copy self.components[n - 1])
+ 0 => None,
+ n => Some(copy self.components[n - 1]),
}
}
fn filestem(&self) -> Option<~str> {
match self.filename() {
- None => None,
- Some(ref f) => {
- match str::rfind_char(*f, '.') {
- Some(p) => Some(f.slice(0, p).to_owned()),
- None => Some(copy *f)
+ None => None,
+ Some(ref f) => {
+ match str::rfind_char(*f, '.') {
+ Some(p) => Some(f.slice(0, p).to_owned()),
+ None => Some(copy *f),
+ }
}
- }
}
}
fn filetype(&self) -> Option<~str> {
match self.filename() {
- None => None,
- Some(ref f) => {
- match str::rfind_char(*f, '.') {
- Some(p) if p < f.len() => Some(f.slice(p, f.len()).to_owned()),
- _ => None
+ None => None,
+ Some(ref f) => {
+ match str::rfind_char(*f, '.') {
+ Some(p) if p < f.len() => Some(f.slice(p, f.len()).to_owned()),
+ _ => None,
+ }
}
- }
}
}
fn with_dirname(&self, d: &str) -> PosixPath {
let dpath = PosixPath(d);
match self.filename() {
- Some(ref f) => dpath.push(*f),
- None => dpath
+ Some(ref f) => dpath.push(*f),
+ None => dpath,
}
}
fn with_filestem(&self, s: &str) -> PosixPath {
match self.filetype() {
- None => self.with_filename(s),
- Some(ref t) => self.with_filename(str::to_owned(s) + *t)
+ None => self.with_filename(s),
+ Some(ref t) => self.with_filename(str::to_owned(s) + *t),
}
}
None => ~[],
Some(ref f) => ~[copy *f]
};
- return PosixPath { is_absolute: false,
- components: cs }
+ PosixPath {
+ is_absolute: false,
+ components: cs,
+ }
}
fn push_rel(&self, other: &PosixPath) -> PosixPath {
fn unsafe_join(&self, other: &PosixPath) -> PosixPath {
if other.is_absolute {
- PosixPath { is_absolute: true,
- components: copy other.components }
+ PosixPath {
+ is_absolute: true,
+ components: copy other.components,
+ }
} else {
self.push_rel(other)
}
}
v.push_all_move(ss);
}
- PosixPath { is_absolute: self.is_absolute,
- components: v }
+ PosixPath {
+ is_absolute: self.is_absolute,
+ components: v,
+ }
}
fn push(&self, s: &str) -> PosixPath {
if cs.len() != 0 {
cs.pop();
}
- return PosixPath {
+ PosixPath {
is_absolute: self.is_absolute,
- components: cs
- }
- //..self }
+ components: cs,
+ } //..self }
}
fn normalize(&self) -> PosixPath {
- return PosixPath {
+ PosixPath {
is_absolute: self.is_absolute,
- components: normalize(self.components)
- // ..self
- }
+ components: normalize(self.components),
+ } // ..self }
}
fn is_absolute(&self) -> bool {
components.push(s.to_owned())
}
let is_absolute = (rest.len() != 0 && windows::is_sep(rest[0]));
- return WindowsPath { host: host,
- device: device,
- is_absolute: is_absolute,
- components: components }
+ WindowsPath {
+ host: host,
+ device: device,
+ is_absolute: is_absolute,
+ components: components,
+ }
}
fn dirname(&self) -> ~str {
fn filename(&self) -> Option<~str> {
match self.components.len() {
- 0 => None,
- n => Some(copy self.components[n - 1])
+ 0 => None,
+ n => Some(copy self.components[n - 1]),
}
}
fn filestem(&self) -> Option<~str> {
match self.filename() {
- None => None,
- Some(ref f) => {
- match str::rfind_char(*f, '.') {
- Some(p) => Some(f.slice(0, p).to_owned()),
- None => Some(copy *f)
+ None => None,
+ Some(ref f) => {
+ match str::rfind_char(*f, '.') {
+ Some(p) => Some(f.slice(0, p).to_owned()),
+ None => Some(copy *f),
+ }
}
- }
}
}
None => None,
Some(ref f) => {
match str::rfind_char(*f, '.') {
- Some(p) if p < f.len() => Some(f.slice(p, f.len()).to_owned()),
- _ => None
+ Some(p) if p < f.len() => Some(f.slice(p, f.len()).to_owned()),
+ _ => None,
}
}
}
fn with_dirname(&self, d: &str) -> WindowsPath {
let dpath = WindowsPath(d);
match self.filename() {
- Some(ref f) => dpath.push(*f),
- None => dpath
+ Some(ref f) => dpath.push(*f),
+ None => dpath,
}
}
fn with_filestem(&self, s: &str) -> WindowsPath {
match self.filetype() {
- None => self.with_filename(s),
- Some(ref t) => self.with_filename(str::to_owned(s) + *t)
+ None => self.with_filename(s),
+ Some(ref t) => self.with_filename(str::to_owned(s) + *t),
}
}
}
fn file_path(&self) -> WindowsPath {
- let cs = match self.filename() {
- None => ~[],
- Some(ref f) => ~[copy *f]
- };
- return WindowsPath { host: None,
- device: None,
- is_absolute: false,
- components: cs }
+ WindowsPath {
+ host: None,
+ device: None,
+ is_absolute: false,
+ components: match self.filename() {
+ None => ~[],
+ Some(ref f) => ~[copy *f],
+ }
+ }
}
fn push_rel(&self, other: &WindowsPath) -> WindowsPath {
host: Some(host),
device: copy other.device,
is_absolute: true,
- components: copy other.components
+ components: copy other.components,
};
}
_ => {}
host: None,
device: Some(device),
is_absolute: true,
- components: copy other.components
+ components: copy other.components,
};
}
_ => {}
host: copy self.host,
device: copy self.device,
is_absolute: self.is_absolute || other.is_absolute,
- components: copy other.components
+ components: copy other.components,
}
}
v.push_all_move(ss);
}
// tedious, but as-is, we can't use ..self
- return WindowsPath {
+ WindowsPath {
host: copy self.host,
device: copy self.device,
is_absolute: self.is_absolute,
ss.push(s.to_owned())
}
v.push_all_move(ss);
- return WindowsPath { components: v, ..copy *self }
+ WindowsPath { components: v, ..copy *self }
}
fn pop(&self) -> WindowsPath {
if cs.len() != 0 {
cs.pop();
}
- return WindowsPath {
+ WindowsPath {
host: copy self.host,
device: copy self.device,
is_absolute: self.is_absolute,
- components: cs
+ components: cs,
}
}
fn normalize(&self) -> WindowsPath {
- return WindowsPath {
+ WindowsPath {
host: copy self.host,
device: match self.device {
None => None,