---
# System prepended metadata

title: Policy code

---

# Policy code
``` rust
trait Policy<A> {
    fn export_check(self, ctxt); /* how to represent ctxt? */
    fn merge(self, _other Policy<A>);
}

impl ops::Add<Policy<Number>> for Policy<Number> {
    fn add(self, _rhs: Policy<Number>) {
        Policy<Number> {
            fn export_check(self, ctxt) {
                // check if policies are of the same type, run just one of them 
                // else run both
            }
            fn merge(self, _other Policy<Number>) {
                self.merge(_other)
            }
        }
    }
}

trait GradePolicy : Policy<Grade> {
    fn check_acl(...);
}



struct GradeNumber(i32);

impl Policy<Number> for GradeNumber {
    fn export_check(self, ctxt) {
        // how do we access the fields of grade??
    }
    fn merge(self, _other Policy<Number>) {
        //
    }
}

struct Grade {
    studentid: Number, 
    grade: GradeNumber, 
};

impl GradePolicy for Grade {
    fn export_check(self, ctxt) {
        // how do we access the fields of grade??
    }
    fn merge(self, _other Policy<Number>) {
        //
    }
    // create methods that return Policy<Num> for fields
}





```

# General Questions
1. How do we want to represent contexts? 
2. Does our current model allow for different policies for different data objects of the same type? (For example, we want to make sure that not all numbers are required to have the same policy.)
3. Is there anthing else that the policy needs to hold when attached to a piece of data? (In our code excerpt above, we're a bit worried about the fact that GradePolicy may not actually have access to the rest of the information stored in Grade—does it need to?)

### Possible Ways to Contain Policies
1. **Have separate structs for `GradePolicy` and `Grade`:** 
    Our concern with this comes down to the fact that we don't necessarily know what information should be stored where. 
    
    
### Filter context
* What type of i/o
    * enum of all possible context types (export_check matches some): 
        * network
        * DB write
        * sys.out
        * RPC
        * HTTPRequest
* To who
* For what purpose

### Plan
* Impl basic structure for grade example, with user-defined types
* Filter obj prototype (writing to file or network socket -- stdlib BufferedWriter)
* Impl for types that we don't define (Num, Str) -- create wrapper types, ensure wrapper types remain preserved