[rust-dev] idea: access modifiers as part of function signature

Rick Richardson rick.richardson at gmail.com
Sat Apr 7 07:01:02 PDT 2012


http://doc.rust-lang.org/doc/tutorial.html#argument-passing

This isn't the most detailed treatise on arguments and ptrs in Rust,
but could you describe a use-case
where ro/rw/out modifiers would be beneficial over what currently exists?


On Sat, Apr 7, 2012 at 9:36 AM, Kobi Lurie <kobi2187 at gmail.com> wrote:
> Thanks for the prompt answers :-)
>
> What do you think of explicitly defining what a function can do with a
> certain argument?
> I talk about adding keywords such as: ro (readonly), rw (readwrite), wo
> (writeonly), unused.
> I think this can help in finding a bug, by shortening the "search space" -
> the argument was readonly so it wasn't changed here..
> it's also less of a mental burden than thinking about pointers/references.
> C# also has the 'out' modifier for writeonly.
>
> this can make things more clear about permission/ownership.
>
> (I know that when passing by value, this somewhat achieves readonly, as the
> value passed will not have effects beyond the function scope.)
>
> The more fleshed out suggestion is that the compiler will force writing or
> removing these modifiers according to the function body.
> I am not sure whether interfaces should include or not include these
> modifiers on the function signatures.
>
> I have a few ideas, and the thought is perhaps a young language would be
> more open to consider them.
>
> see you, Kobi
> _______________________________________________
> Rust-dev mailing list
> Rust-dev at mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev


More information about the Rust-dev mailing list