master > master: code-rust - init

This commit is contained in:
RD
2022-04-08 07:26:56 +02:00
parent 3338b255a1
commit b85574cda4
6 changed files with 187 additions and 3 deletions

View File

@@ -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);
}