use std::fmt;
use std::ops::{Index,IndexMut};
#[derive(Debug)]
struct CharString {
val: Vec<char>,
len: usize
}
#[allow(non_snake_case)]
fn CharString (s: Vec<char>) -> CharString {
let l = s.len();
CharString{val: s, len: l}
}
impl fmt::Display for CharString {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s: String = self.val.iter().collect();
write!(f, "{}", s)
}
}
impl Index<usize> for CharString {
type Output = char;
fn index(&self, index: usize) -> &Self::Output {
&self.val[index]
}
}
impl IndexMut<usize> for CharString {
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
&mut self.val[index]
}
}
fn main() {
let cvec: CharString = CharString("λs.s".chars().collect());
println!("{}", cvec);
println!("{}", cvec[0]);
}