Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protocol: Guarantee #62

Closed
oscbyspro opened this issue Aug 6, 2024 · 4 comments
Closed

Protocol: Guarantee #62

oscbyspro opened this issue Aug 6, 2024 · 4 comments
Labels
addition oh, so shiny!

Comments

@oscbyspro
Copy link
Owner

oscbyspro commented Aug 6, 2024

Trusted inputs have multiple conveniences that can be derived from a simple protocol:

protocol Guarantee<Value> {

    associatedtype Value
    
    static func predicate(_ value: borrowing Value) -> Bool
    
    init(unchecked value: consuming Value)
}
@oscbyspro oscbyspro added the addition oh, so shiny! label Aug 6, 2024
@oscbyspro
Copy link
Owner Author

The only problem is that it duplicates validation checks in debug mode, but I also don't want init(unsafe:).

@oscbyspro
Copy link
Owner Author

oscbyspro commented Aug 6, 2024

Hm. I could require that it only stores its value, adding some abstract capabilities. Alternatively, I can omit that and mark Divider<T> (#58) as a Guarantee. I mean, it's basically a trusted input with some additional data.

@oscbyspro oscbyspro modified the milestone: Ultimathnum 0.8.0 Aug 6, 2024
@oscbyspro oscbyspro added the maybe to do, or not to do? label Aug 6, 2024
@oscbyspro
Copy link
Owner Author

Meh. It's not enough boilerplate to worry about.

@oscbyspro oscbyspro closed this as not planned Won't fix, can't repro, duplicate, stale Aug 6, 2024
oscbyspro added a commit that referenced this issue Aug 7, 2024
oscbyspro added a commit that referenced this issue Aug 7, 2024
@oscbyspro oscbyspro reopened this Aug 29, 2024
@oscbyspro
Copy link
Owner Author

oscbyspro commented Aug 29, 2024

I might want to add this kind of protocol simply to aid prototyping of various trusted input types (#78). It also simplifies testing since derived operations are identical for all types. Something like the following, perhaps?

public protocol Guarantee<Value> {
    
    associatedtype Value
    
    @inlinable static func predicate(_ value: borrowing Value) -> Bool
    
    @inlinable init(unsafe value: consuming Value)
        
    @inlinable consuming func payload() ->  Value
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition oh, so shiny!
Projects
None yet
Development

No branches or pull requests

1 participant