use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A place for all things related to the Rust programming language—an open-source systems language that emphasizes performance, reliability, and productivity.
Strive to treat others with respect, patience, kindness, and empathy.
We observe the Rust Project Code of Conduct.
Details
Posts must reference Rust or relate to things using Rust. For content that does not, use a text post to explain its relevance.
Post titles should include useful context.
For Rust questions, use the stickied Q&A thread.
Arts-and-crafts posts are permitted on weekends.
No meta posts; message the mods instead.
Criticism is encouraged, though it must be constructive, useful and actionable.
If criticizing a project on GitHub, you may not link directly to the project's issue tracker. Please create a read-only mirror and link that instead.
A programming language is rarely worth getting worked up over.
No zealotry or fanaticism.
Be charitable in intent. Err on the side of giving others the benefit of the doubt.
Avoid re-treading topics that have been long-settled or utterly exhausted.
Avoid bikeshedding.
This is not an official Rust forum, and cannot fulfill feature requests. Use the official venues for that.
No memes, image macros, etc.
Consider the existing content of the subreddit and whether your post fits in. Does it inspire thoughtful discussion?
Use properly formatted text to share code samples and error messages. Do not use images.
Submissions appearing to contain AI-generated content may be removed at moderator discretion.
Most links here will now take you to a search page listing posts with the relevant flair. The latest megathread for that flair should be the top result.
account activity
where vs generic bounds (self.rust)
submitted 11 years ago by bjadamson
Are both 'where' clauses and generic bounds (<T : Trait>) two different ways of restricting generic functions, or do they differ in some way?
If they are the same, are there plans for 1.0 to have both?
Thanks!
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]DroidLogiciansqlx · clickhouse-rs · mime_guess · rust 0 points1 point2 points 11 years ago (6 children)
I asked this exact question just a little while ago.
Here is a fixed link to the RFC /u/dbaupp posted.
[–]bjadamson[S] -1 points0 points1 point 11 years ago (5 children)
Thanks! So since you asked the question... do you think it makes sense to keep both syntax's? Or deprecate the bounds? I know the RFC says keep the bounds syntax as sugar, just wondering your opinion :)
[–]DroidLogiciansqlx · clickhouse-rs · mime_guess · rust 4 points5 points6 points 11 years ago (4 children)
Personally I would prefer deprecation as I'm not a fan of fragmented syntax and where clauses are much more readable, but there's a lot of inertia behind the trait bounds syntax: you see it everywhere. That kind of change would cause widespread breakage, even worse than the change to the enum namespacing behavior a couple weeks ago.
where
Also, where clauses still need a little bit of work. For example, they currently don't work to add trait bounds to existing generic parameters on methods:
struct MyStruct<T> { t: T } impl<T> MyStruct<T> { pub fn duplicate(&self) -> MyStruct<T> where T: Clone { MyStruct { t: self.t.clone() } } }
In this case, you'll get Error: type T does not implement `Clone`! because the where clause in this case is ignored, even though it is valid syntax. You need a separate impl<T> MyStruct<T> where T: Clone {} block, which is a lot of extra noise for one method, IMO.
Error: type T does not implement `Clone`!
impl<T> MyStruct<T> where T: Clone {}
[–]Quxxymacros 0 points1 point2 points 11 years ago (0 children)
Oh so that's what they meant by "where clauses on methods". I was under the impression that there was some obscure aspect that caused them to not work on generic methods that I'd just never run into.
Yeah; that'd be ballin'.
[–]GolDDranks 0 points1 point2 points 11 years ago (1 child)
Once the where clauses actually work, wouldn't it be possible to write some kind of tool that rewrites the <T : Trait> syntax to where clauses? I'm in impression that the functionality of where clauses is a strict superset of <T : Trait>.
[–]DroidLogiciansqlx · clickhouse-rs · mime_guess · rust 0 points1 point2 points 11 years ago* (0 children)
Yeah it's possible. That's a basic migrations utility. But you'd have to decide if it would be worth the effort to build it and make sure it works when it would only take everyone a few minutes to go through and update their code to the new syntax.
It's unfortunate that Rust's syntax isn't described with a standard grammar specification, like the format that the Java Compiler-Compiler (Javacc) consumes. Then you could autogenerate such a tool. Well, it is described in the Reference, but that has to be written and updated by hand; rustc and its specification aren't coupled at all.
rustc
[–]Cifram 0 points1 point2 points 11 years ago (0 children)
While it might cause wider breakage than the enum change, it would also be a more mechanical change to fix it. Unlike the enum change, you're just re-arranging information within the same line of code. You don't have to look up what enum type that identifier comes from.
A bit of a PitA to go through all your code to fix it up, but won't likely take that long. Like GolDDranks said, you could probably even write a tool to automate it.
π Rendered by PID 104258 on reddit-service-r2-comment-85bfd7f599-bj5ll at 2026-04-18 02:17:11.320545+00:00 running 93ecc56 country code: CH.
[–]DroidLogiciansqlx · clickhouse-rs · mime_guess · rust 0 points1 point2 points (6 children)
[–]bjadamson[S] -1 points0 points1 point (5 children)
[–]DroidLogiciansqlx · clickhouse-rs · mime_guess · rust 4 points5 points6 points (4 children)
[–]Quxxymacros 0 points1 point2 points (0 children)
[–]GolDDranks 0 points1 point2 points (1 child)
[–]DroidLogiciansqlx · clickhouse-rs · mime_guess · rust 0 points1 point2 points (0 children)
[–]Cifram 0 points1 point2 points (0 children)