Skip to content

Instantly share code, notes, and snippets.

@bpicolo
Created November 27, 2014 16:16
Show Gist options
  • Save bpicolo/931077eb317fe146a4b6 to your computer and use it in GitHub Desktop.
Save bpicolo/931077eb317fe146a4b6 to your computer and use it in GitHub Desktop.
pub trait Html {
fn tag(&self) -> String;
fn closing_tag(&self) -> bool;
fn attrs(&self) -> String;
}
pub struct Input<'a> {
attributes: HashMap<String, String>,
field: Field<'a>,
}
impl<'a> Html for Input<'a> {
fn tag(&self) -> String {
return String::from_str("input");
}
fn closing_tag(&self) -> bool {true}
fn attrs(&self) -> String {
return String::from_str("class=\"value\"");
}
}
#[cfg(test)]
mod test {
use validator::{Validator, Integer, Range};
use std::collections::HashMap;
use super::Input;
use field::Field;
#[test]
fn test_empty_field() {
let input = Input{field: Field::new(), attributes: HashMap::new()};
println!("attrs is {}", input.attrs());
println!("tag is {}", input.tag());
}
}
Issues when running test:
input.rs:42:39: 42:46 error: type `input::Input<'_>` does not implement any method in scope named `attrs`
input.rs:42 println!("attrs is {}", input.attrs());
^~~~~~~
input.rs:43:37: 43:42 error: type `input::Input<'_>` does not implement any method in scope named `tag`
input.rs:43 println!("tag is {}", input.tag());
is this a lifetimes issue?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment