-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

        Dear Rusties (?),
  I am in the process of designing a small rope library for Rust and I
have a few issues wrt `str`. I am a newbie at Rust, so I may be wrong,
but it is my understanding that `str` supports a form of mutability
through an in-place append operation `+=`.

 By opposition, ropes rely very much on the immutability of text
strings to allow sharing, log-time subrope extraction, log-time access
at index even with Unicode, etc.

In the current wip version of my API, ropes interact with strings
essentially through the following functions:

//adopt a string as a rope
rope::of_str(str) -> rope

//adopt a substring as a rope
rope::of_str_range(str, uint, uint) -> rope

//loop through the str components of a rope – useful for outputs
rope::traverse_components(rope, block(str))

If type `str` is indeed (at least partly) mutable, each of these
functions must copy the `str`, which is rather costly. I wonder if
there is a type-based mechanism that I could use to guarantee that a
`str` is never mutated, hopefully some trivial typestate-based pattern
that currently escapes my grasp.

Note that, if typestate does not allow this kind of thing yet, there
are good chances that we can obtain this feature without changing the
type system. For comparison, in OCaml Batteries Included, there is a
type `ACString.t` ("AC" stands for access control) which uses phantom
types to distribute read/write rights to strings. If anybody is
interested, I can detail how it works and/or attempt to port it to Rust.

Cheers,
 David

P.S.: It is my understanding that operation `+=` to `str` was added to
simplify serialization. If we have a satisfactory implementation of
ropes, perhaps an operation `+=` on `@mutable rope` would prove more
appropriate?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJOrbk+AAoJED+FkPgNe9W+yiwIALu/zqbXjVlaUp1WbBB/xspM
/kP9iiLdmUIbRTyJR6GDfNqeJyWIo1vq5LiSwAisciZMkypW/8sIaN47p2qYDiMa
uQulBbv2H88R53xBmOjkWqfziRsPAogdNU3c/9pABTBv6KQ2FLT/8bvagSw0LFUm
Cj4/mYN6xPJhS5OwUs2SiqKff2wTxU5DTfRDFF+SvTtI6l2TBI2e2rYTKTPWFoWj
RvacIUsqXL8l1tyFBVHfxrCsaZVUHqf8nO+RWDfrY+j/Zrv9JBN90/c3AD9hVYib
x/wIJ1nuYlg1YVXlrCG+67BCe7pxX/l2GTAqvWzxGd0fcIg3V0an6gspyvyLRps=
=bBEk
-----END PGP SIGNATURE-----
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to