随笔分类 - rust
摘要:path = r'\\c价.xlsx' df = pd.read_excel(path) df = df.sort_values(by='YM', ascending=False) df.dropna(inplace=True) df['cc'] = np.where(df['单价'].str.is
阅读全文
摘要:use chrono::prelude::*; // 1. 时间转字符 // 2. 字符转时间 // 3. 时间相加减 // 4. 时间加差异数 fn main(){ let d = NaiveDate::from_ymd(2015, 3, 14); let a = NaiveDate::from_
阅读全文
摘要:use std::cmp::Ordering; enum Fruit { Apple(i32), Orange(i32), } fn process_fruit(_apple_prices: &[i32], _orange_prices: &[i32]) { // whatever we do to
阅读全文
摘要:https://zhuanlan.zhihu.com/p/492292655
阅读全文
摘要:#[derive(Debug)] enum Unit{ INT(i32), STR(String), FLOAT(f32) } #[derive(Debug)] struct People{ name: String, elements: Vec<Unit> } impl IntoIterator
阅读全文
摘要:struct CountdownIterator(i32); impl Iterator for CountdownIterator { type Item = i32; fn next(&mut self) -> Option<Self::Item> { self.0 -= 1; if self.
阅读全文
摘要:use std::ptr; use std::fmt::{ Display, Formatter, Result }; pub struct Node { value: i32, next: *mut Node } impl Node { pub fn new(val: i32) -> Self {
阅读全文
摘要:通过迭代器提供的filter()和collect()方法。 let list2: Vec<_> = (1..=100).filter(|i| i%3 == 0).collect();assert_eq!(list1, list2); take(k)取前面k个元素。 迭代器调用take()后,迭代器的
阅读全文
摘要:use postgres::{Client, NoTls}; fn main(){ let mut client = Client::connect("host=localhost user=postgres password=postgres port=5433", NoTls).unwrap()
阅读全文
摘要:use std::fmt::{Debug, Display}; use std::any::TypeId; use std::any::Any; fn is_string<T: ?Sized + Any>(_s: &T) -> bool { TypeId::of::<String>() == Typ
阅读全文
摘要:mopa = 0.2 use mopa; use std::fmt::Debug; use std::fmt::Display; use std::any::TypeId; fn is_string<T: ?Sized + mopa::Any>(_s: &T) -> bool { TypeId::o
阅读全文
摘要:#[macro_use] extern crate mopa; struct Bear { // This might be a pretty fat bear. fatness: u16, } impl Bear { fn eat(&mut self, person: Box<dyn Person
阅读全文
摘要:downcast-rs = "1.2" // Can call macro via namespace since rust 1.30. use downcast_rs::Downcast; use std::fmt::Debug; // To create a trait with downcas
阅读全文
摘要:use std::any::Any; use core::fmt::Debug; trait ColTrait: std::fmt::Debug{ fn getself<T>(&self)->T; } #[derive(Debug)] struct DataCell<T>{ val:T, } //
阅读全文
摘要:use std::{any::{Any, TypeId}, fmt::Debug}; use downcast_rs::Downcast; fn is_string<T: ?Sized + Any>(_s: &T) -> bool { TypeId::of::<String>() == TypeId
阅读全文
摘要:use std::collections::HashMap; use std::ops::Index; #[derive(Debug,Clone)] struct Cell{ name:String } type Col = HashMap<String, Vec<Cell>>; #[derive(
阅读全文
摘要:trait Select<T>{ fn select<'a>(self, slice:&'a Vec<T>)->Vec<&T>; } impl<T> Select<T> for usize { fn select<'a>(self, slice:&'a Vec<T>)->Vec<&T> { matc
阅读全文
摘要:#[derive(Clone, Copy)] enum Args<'a> { Idx(usize), IdxList(&'a [usize]), } fn get_data<'a, T>(arr: &'a [T], idxs: Args<'a>) -> Vec<&'a T> { match idxs
阅读全文
摘要:use std::any::Any; macro_rules! requests{ ( $($key:expr=> $value:expr);* $(;)? ) => { let mut url: Box<dyn Any> = Box::new(""); let mut method: Box<dy
阅读全文
摘要:#[derive(Debug)] enum Cell{ s(String), f(f64), i(i64), b(bool) } #[derive(Debug)] struct Col{ title:String, data:Vec<Cell> } type DataFrame = Vec<Col>
阅读全文