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

Rust: questions and comments #3

Open
jblachly opened this issue Aug 11, 2021 · 2 comments
Open

Rust: questions and comments #3

jblachly opened this issue Aug 11, 2021 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@jblachly
Copy link
Member

  1. is bkind necessary in the Coordinates type
  2. Would rename Coordinates to Interval
  3. Should to be into?
@jblachly jblachly added the question Further information is requested label Aug 11, 2021
@charlesgregory
Copy link
Contributor

With latest commits questions 1 and 2 are addressed.
As for question 3:
The rust API guidelines on conversion state:

Conversions prefixed as_ and into_ typically decrease abstraction, either exposing a view into the underlying representation (as) or deconstructing data into its underlying representation (into).

Conversions prefixed to_, on the other hand, typically stay at the same level of abstraction but do some work to change from one representation to another.

So I think to is appropriate.

@jblachly
Copy link
Member Author

jblachly commented Sep 2, 2021

So I re-read the linked page (which incidentally I could only find by coming back here, no matter what combinatin of google search terms I used, I couldn't find it again :/) and something stands out, namely that into is for owned->owned, and will consume the input.

That looks exactly like what your functions are doing:

impl Interval<ZeroBased, HalfOpen>{
    pub fn to<ToBs: Basis, ToEd: End>(&self) -> Interval<ToBs, ToEd>{
        let mut ret = Interval::<ToBs, ToEd>::from_int(self.start.pos, self.end.pos);
        if !ToBs::IS_ZERO_BASED {
            ret.start.pos += 1;
            ret.end.pos += 1;
        }
        if !ToEd::IS_EXCLUSIVE {
            ret.end.pos -= 1;
        }
        ret
    }
}

@jblachly jblachly reopened this Sep 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants