python;gutter:true;
use std::collections::HashMap;
use std::ops::Index;</p>
<h1>[derive(Debug,Clone)]</h1>
<p>struct Cell{
name:String
}
type Col = HashMap>;</p>
<h1>[derive(Debug,Clone)]</h1>
<p>struct DF{
columns: Vec
}</p>
<p>impl Index for DF{
type Output = i32;
fn index(&self, c:&str)->&i32 {
println!("索引字符是: {}", &c);</p>
<pre><code> &2_i32
}
</code></pre>
<p>}</p>
<p>fn main() {
let mut a = HashMap::new();
a.insert(String::from("A"), vec![Cell{name:String::from("A1")}, Cell{name:String::from("A2")}]);
let mut b = HashMap::new();
b.insert(String::from("B"), vec![Cell{name:String::from("B1")}, Cell{name:String::from("B2")}]);
let df = DF{ columns:vec![a, b]};
println!("{:?}", df["C"]);
}
Original: https://www.cnblogs.com/pythonClub/p/16498159.html
Author: CrossPython
Title: rust index
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/15798/
转载文章受原作者版权保护。转载请注明原作者出处!