随笔分类 -  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 阅读全文
posted @ 2022-08-03 10:38 CrossPython 阅读(381) 评论(0) 推荐(0)
摘要:use chrono::prelude::*; // 1. 时间转字符 // 2. 字符转时间 // 3. 时间相加减 // 4. 时间加差异数 fn main(){ let d = NaiveDate::from_ymd(2015, 3, 14); let a = NaiveDate::from_ 阅读全文
posted @ 2022-08-02 16:41 CrossPython 阅读(263) 评论(0) 推荐(0)
摘要:use std::cmp::Ordering; enum Fruit { Apple(i32), Orange(i32), } fn process_fruit(_apple_prices: &[i32], _orange_prices: &[i32]) { // whatever we do to 阅读全文
posted @ 2022-08-01 11:17 CrossPython 阅读(54) 评论(0) 推荐(0)
摘要:https://zhuanlan.zhihu.com/p/492292655 阅读全文
posted @ 2022-07-30 15:06 CrossPython 阅读(45) 评论(0) 推荐(0)
摘要:#[derive(Debug)] enum Unit{ INT(i32), STR(String), FLOAT(f32) } #[derive(Debug)] struct People{ name: String, elements: Vec<Unit> } impl IntoIterator 阅读全文
posted @ 2022-07-28 13:36 CrossPython 阅读(20) 评论(0) 推荐(0)
摘要:struct CountdownIterator(i32); impl Iterator for CountdownIterator { type Item = i32; fn next(&mut self) -> Option<Self::Item> { self.0 -= 1; if self. 阅读全文
posted @ 2022-07-28 12:26 CrossPython 阅读(20) 评论(0) 推荐(0)
摘要: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 { 阅读全文
posted @ 2022-07-28 11:52 CrossPython 阅读(26) 评论(0) 推荐(0)
摘要:通过迭代器提供的filter()和collect()方法。 let list2: Vec<_> = (1..=100).filter(|i| i%3 == 0).collect();assert_eq!(list1, list2); take(k)取前面k个元素。 迭代器调用take()后,迭代器的 阅读全文
posted @ 2022-07-28 10:39 CrossPython 阅读(59) 评论(0) 推荐(0)
摘要:use postgres::{Client, NoTls}; fn main(){ let mut client = Client::connect("host=localhost user=postgres password=postgres port=5433", NoTls).unwrap() 阅读全文
posted @ 2022-07-27 13:46 CrossPython 阅读(77) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2022-07-25 22:01 CrossPython 阅读(23) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2022-07-25 18:38 CrossPython 阅读(19) 评论(0) 推荐(0)
摘要:#[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 阅读全文
posted @ 2022-07-25 18:28 CrossPython 阅读(23) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2022-07-24 09:53 CrossPython 阅读(106) 评论(0) 推荐(0)
摘要: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, } // 阅读全文
posted @ 2022-07-21 13:26 CrossPython 阅读(66) 评论(0) 推荐(0)
摘要:use std::{any::{Any, TypeId}, fmt::Debug}; use downcast_rs::Downcast; fn is_string<T: ?Sized + Any>(_s: &T) -> bool { TypeId::of::<String>() == TypeId 阅读全文
posted @ 2022-07-21 09:19 CrossPython 阅读(50) 评论(0) 推荐(0)
摘要:use std::collections::HashMap; use std::ops::Index; #[derive(Debug,Clone)] struct Cell{ name:String } type Col = HashMap<String, Vec<Cell>>; #[derive( 阅读全文
posted @ 2022-07-20 15:20 CrossPython 阅读(56) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2022-07-16 23:41 CrossPython 阅读(18) 评论(0) 推荐(0)
摘要:#[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 阅读全文
posted @ 2022-07-16 17:54 CrossPython 阅读(65) 评论(0) 推荐(0)
摘要:use std::any::Any; macro_rules! requests{ ( $($key:expr=> $value:expr);* $(;)? ) => { let mut url: Box<dyn Any> = Box::new(""); let mut method: Box<dy 阅读全文
posted @ 2022-07-16 15:26 CrossPython 阅读(130) 评论(0) 推荐(0)
摘要:#[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> 阅读全文
posted @ 2022-07-16 11:54 CrossPython 阅读(10) 评论(0) 推荐(0)