I'm not sure I understand your question, but if I guessed correctly:
Are you want to write something like this?
~~~~
fn conditionally_return(cond: bool, p: ~str, q: ~[u8]) -> Either<~str,~[u8]> {
if cond { Left(p) } else { Right(q) }
}
~~~~
If you have four cases, then you must make an enum with four variants
(a bit cumbersome). As you expected, the compiler *cannot* infer that
some of arguments will have to be freed according to the internal
state, but you can manually list the possible cases to let the
compiler aware of them.
2013/11/17 spir <[email protected]>:
> Hello,
>
> say a function defines 4 pointed elements of data. Depending on logical
> conditions, one of them escapes the func to be assigned to some world
> variable (static or on heap), while another is returned. How does Rust
> determine which of those data are to be freed? Seems this can only be done
> dynamically, at runtime, or do I miss a relevant point? Is there a cheap
> algo to do this?
> (Also, those elements of data can be arbitrarily complex, and hold other
> pointed data which themselves may be placed there conditionally.)
>
> Thank you,
> denis
>
> _______________________________________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev
--
-- Kang Seonghoon | Software Engineer, iPlateia Inc. | http://mearie.org/
-- Opinions expressed in this email do not necessarily represent the
views of my employer.
--
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev