1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! # Flag
//! 
//! The flag module reads flag arguments implementing get::SGetter
//! 

use std::env;
use get::SGetter;

/// The function that does the actual work. It read's through the programs arguments looking for a
/// match, and returns the argument after the match.
pub fn ss_get(s:&str, iter:&mut Iterator<Item=String>)->Option<String>{
    let mut fnd = false;
    for a in iter{
        if fnd {
            return Some(a.clone());
        }
        if a == s {
            fnd = true;
        }
    }

    if fnd { return Some(String::from(""));}

    None
}

pub struct Fg{}
    
pub struct FgTest{
    v:Vec<String>,
}

impl <'a> SGetter<&'a str> for Fg{
    fn get_s(&self,s:&str)->Option<String>{
        return ss_get(&s,&mut env::args())
    }
}

impl <'a> SGetter<&'a str> for FgTest{
    fn get_s(&self,s:&str)->Option<String>{
        ss_get(s,&mut self.v.clone().into_iter())
    }
}


impl FgTest{
    pub fn new(v:Vec<String>)->FgTest{
        FgTest{
            v:v,
        }
    }
}