master > master: code-rust - init
This commit is contained in:
@@ -11,15 +11,45 @@ use self::regex::Regex;
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
/// Constructs RegEx and panics if error.
|
||||
#[allow(dead_code)]
|
||||
pub fn construct_regex(pattern: &str) -> Regex {
|
||||
return Regex::new(pattern)
|
||||
.expect("Invalid regex construction!");
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// METHOD hello world
|
||||
// METHODS values
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
pub fn greet() {
|
||||
println!("Hello world!");
|
||||
pub fn min<T>(x: T, y: T) -> T
|
||||
where T: PartialOrd
|
||||
{
|
||||
return if y < x { y } else { x };
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// METHODS Vectors
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
pub fn restrict<T>(x: &mut Vec<T>, i: usize, j: usize) -> Vec<T>
|
||||
where T: Clone
|
||||
{
|
||||
return x[i..j].iter()
|
||||
.cloned()
|
||||
.collect::<Vec<T>>();
|
||||
}
|
||||
|
||||
pub fn remove_last<T>(x: &mut Vec<T>) -> Vec<T>
|
||||
where T: Clone
|
||||
{
|
||||
let n = x.len();
|
||||
return restrict::<T>(x, 0, n-1);
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn remove_first<T>(x: &mut Vec<T>) -> Vec<T>
|
||||
where T: Clone
|
||||
{
|
||||
let n = x.len();
|
||||
return restrict::<T>(x, 0, n);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user