Skip to content

Commit

Permalink
Use four-space indentation, add trailing commas, and remove unnecessa…
Browse files Browse the repository at this point in the history
…ry uses of the return keyword
  • Loading branch information
brendanzab committed May 18, 2013
1 parent 60ea6d6 commit ad6ee5f
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 80 deletions.
26 changes: 16 additions & 10 deletions src/libcore/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ pub enum Either<T, U> {
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)
}
}

Expand Down Expand Up @@ -73,8 +73,8 @@ pub fn partition<T, U>(eithers: ~[Either<T, U>]) -> (~[T], ~[U]) {
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);
Expand All @@ -84,8 +84,8 @@ pub fn partition<T, U>(eithers: ~[Either<T, U>]) -> (~[T], ~[U]) {
#[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)
}
}

Expand All @@ -96,21 +96,27 @@ pub fn flip<T, U>(eith: Either<T, U>) -> Either<U, T> {
#[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.
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ impl<T:Ord> Ord for Option<T> {
}

fn ge(&self, other: &Option<T>) -> bool {
! (self < other)
!(self < other)
}

fn gt(&self, other: &Option<T>) -> bool {
! (self <= other)
!(self <= other)
}
}

Expand Down
145 changes: 77 additions & 68 deletions src/libcore/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,10 @@ impl GenericPath for PosixPath {
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 {
Expand All @@ -466,40 +468,40 @@ impl GenericPath for PosixPath {

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,
}
}

Expand All @@ -510,8 +512,8 @@ impl GenericPath for PosixPath {

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),
}
}

Expand All @@ -536,8 +538,10 @@ impl GenericPath for PosixPath {
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 {
Expand All @@ -547,8 +551,10 @@ impl GenericPath for 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)
}
Expand All @@ -567,8 +573,10 @@ impl GenericPath for PosixPath {
}
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 {
Expand All @@ -586,19 +594,17 @@ impl GenericPath for 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 {
Expand Down Expand Up @@ -658,10 +664,12 @@ impl GenericPath for WindowsPath {
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 {
Expand All @@ -674,20 +682,20 @@ impl GenericPath for WindowsPath {

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),
}
}
}
}
}

Expand All @@ -696,8 +704,8 @@ impl GenericPath for WindowsPath {
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,
}
}
}
Expand All @@ -706,8 +714,8 @@ impl GenericPath for WindowsPath {
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,
}
}

Expand All @@ -718,8 +726,8 @@ impl GenericPath for WindowsPath {

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),
}
}

Expand All @@ -740,14 +748,15 @@ impl GenericPath for WindowsPath {
}

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 {
Expand All @@ -768,7 +777,7 @@ impl GenericPath for WindowsPath {
host: Some(host),
device: copy other.device,
is_absolute: true,
components: copy other.components
components: copy other.components,
};
}
_ => {}
Expand All @@ -781,7 +790,7 @@ impl GenericPath for WindowsPath {
host: None,
device: Some(device),
is_absolute: true,
components: copy other.components
components: copy other.components,
};
}
_ => {}
Expand All @@ -793,7 +802,7 @@ impl GenericPath for WindowsPath {
host: copy self.host,
device: copy self.device,
is_absolute: self.is_absolute || other.is_absolute,
components: copy other.components
components: copy other.components,
}
}

Expand Down Expand Up @@ -822,7 +831,7 @@ impl GenericPath for WindowsPath {
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,
Expand All @@ -837,24 +846,24 @@ impl GenericPath for WindowsPath {
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 {
let mut cs = copy self.components;
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,
Expand Down

5 comments on commit ad6ee5f

@bors
Copy link
Contributor

@bors bors commented on ad6ee5f May 18, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from thestinger
at brendanzab@ad6ee5f

@bors
Copy link
Contributor

@bors bors commented on ad6ee5f May 18, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging bjz/rust/formatting-and-conditionals = ad6ee5f into auto

@bors
Copy link
Contributor

@bors bors commented on ad6ee5f May 18, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bjz/rust/formatting-and-conditionals = ad6ee5f merged ok, testing candidate = e91daaa

@bors
Copy link
Contributor

@bors bors commented on ad6ee5f May 18, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on ad6ee5f May 18, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding incoming to auto = e91daaa

Please sign in to comment.