Rust 1.3 发布,该版本最显著的变化是 announcement API
的稳定性及性能的提升。此外,还有新的子字符串匹配算法,一个快速的
zero-filling 方法用于初始化和调整向量,提升了 Read::read_to_end
函数的速度(via lwn.net)  。

Introduction To Obejct


Rust
1.3发行日志的更新列表如下:

The progress of abstraction

  • But their primary abstraction still requires you to think in terms
    of the structure of the computer rather than the structure of the
    problem youare trying to solve.
  • The alternative to modeling the machine is to model the problem
    you’re trying to solve.
  • We refer to the elements in the problem space and their
    representations in the solution space as “objects.”
  • when you read the code describing the solution, you’re reading words
    that also express the problem.
  • OOP allows you to describe the problem in terms of the problem,
    rather than in terms of the computer where the solution will run.
  • Five basic characteristics:
    1.Everything is an object.
    2.A program is a bunch of objects telling each other what to do by
    sending messages.
    3.Each object has its own memory made up of other objects.
    4.Every object has a type.
    5.All objects of a particular type can receive the same messages.
  • An object has state, behavior and identity: an object can have
    internal data (which gives it state), methods (to produce behavior),
    and each object can be uniquely distinguished from every other
    object(address in memory).

Highlights

  • The new object lifetime
    defaults
    have been turned on
    after a cycle of warnings about the change. Now types like
    &'a Box<Trait> (or &'a Rc<Trait>, etc) will change from being
    interpreted as &'a Box<Trait+'a> to &'a Box<Trait+'static>.

  • The Rustonomicon is a
    new book in the official documentation that dives into writing
    unsafe Rust.

  • The
    Duration
    API, has been
    stabilized. This
    basic unit of timekeeping is employed by other std APIs, as well as
    out-of-tree time crates.

An object has an interface

  • Objects that are identical except for their state during a program’s
    execution are grouped together into “classes of objects,” and that’s
    where the keyword class came from.
  • Each object belongs to a particular class that defines its
    characteristics and behaviors.
  • You extend the programming language by adding new data types
    specific to your needs.
  • Any program is a simulation of the system you’re designing.
  • One of the challenges of object-oriented programming is to create a
    one-to-one mapping between the elements in the problem space and
    objects in the solution space.
  • The requests you can make of an object are defined by its interface,
    and the type is what determines the interface.
  • A type has a method associated with each possible request, and when
    you make a particular request to an object, that method is called.

Breaking Changes

  • The new object lifetime
    defaults
    have been turned on
    after a cycle of warnings about the change.

  • There is a known
    regression in how
    object lifetime elision is interpreted, the proper solution for
    which is undetermined.

  • The #[prelude_import] attribute, an internal implementation
    detail, was accidentally stabilized previously. It has been put
    behind the prelude_import feature
    gate. This change is
    believed to break no existing code.

  • The behavior of
    size_of_val
    and
    align_of_val
    ismore sane for dynamically sized
    types. Code that
    relied on the previous behavior is thought to be broken.

  • The dropck rules, which checks that destructors can’t access
    destroyed values, have been
    updated to match
    theRFC.
    This fixes some soundness holes, and as such will cause some
    previously-compiling code to no longer build.

An object provides services

  • Your program itself will provide services to the user, and it will
    accomplish this by using the services offered by other objects.
  • Thinking of an object as a service provider has an additional
    benefit: It helps to improve the cohesiveness of the object.
  • In a good object-oriented design, each object does one thing well,
    but doesn’t try to do too much.
  • If they can see the value of the object based on what service it
    provides, it makes it much easier to fit it into the design.

Language

  • The new object lifetime
    defaults
    have been turned on
    after a cycle of warnings about the change.

  • Semicolons may now follow types and paths in
    macros.

  • The behavior of
    size_of_val
    and
    align_of_val
    ismore sane for dynamically sized
    types. Code that
    relied on the previous behavior is not known to exist, and suspected
    to be broken.

  • 'static variables may now be
    recursive.

  • ref bindings choose between
    Deref
    and
    DerefMutimplementations
    correctly.

  • The dropck rules, which checks that destructors can’t access
    destroyed values, have been
    updated to match
    theRFC.

The hidden implementation

  • The goal of the class creator is to build a class that exposes only
    what’s necessary to the client programmer and keeps everything else
    hidden.
  • The first reason for access control is to keep client programmers’
    hands off portions they shouldn’t touch.
  • Parts that are necessary for the internal operation of the data type
    but not part of the interface that users need in order to solve
    their particular problems.
  • The second reason for access control is to allow the library
    designer to change the internal workings of the class without
    worrying about how it will affect the client programmer.

Libraries

  • The
    Duration
    API, has been
    stabilized, as well
    as thestd::time module, which presently contains only Duration.

  • Box<str>澳门新葡亰游戏网址, and Box<[T]> both implement Clone.

  • The owned C string,
    CString,
    implements
    Borrow
    and the borrowed C string,
    CStr,
    implements
    ToOwned.
    The two of these allow C strings to be borrowed and cloned in
    generic code.

  • CStr
    implements
    Debug.

  • AtomicPtr
    implements
    Debug.

  • Error
    trait objects can be downcast to their concrete
    typesin many common
    configurations, using the
    is,
    downcast,downcast_ref
    and
    downcast_mut
    methods, similarly to
    theAny
    trait.

  • Searching for substrings now employs the two-way
    algorithminstead of
    doing a naive search. This gives major speedups to a number of
    methods, including
    contains,
    find,rfind,
    split.
    starts_with
    andends_with
    are also faster.

  • The performance of PartialEq for slices is much
    faster.

  • The
    Hash
    trait offers the default method,
    hash_slice,
    which is overridden and optimized by the implementations for
    scalars.

  • The
    Hasher
    trait now has a number of specialized write_*methods for primitive
    types, for efficiency.

  • The I/O-specific error type,
    std::io::Error,
    gained a set of methods for accessing the ‘inner error’, if any:
    get_ref,get_mut,
    into_inner.
    As well, the implementation of
    std::error::Error::cause
    also delegates to the inner error.

  • process::Child
    gained the
    id
    method, which returns au32 representing the platform-specific
    process identifier.

  • The
    connect
    method on slices is deprecated, replaced by the
    newjoin
    method (note that both of these are on the
    unstableSliceConcatExt
    trait, but through the magic of the prelude are available to stable
    code anyway).

  • The Div
    operator is implemented for
    Wrapping
    types.

  • DerefMut is implemented for
    String.

  • Performance of SipHash (the default hasher for HashMap) isbetter
    for long data.

  • AtomicPtr
    implements
    Send.

  • The
    read_to_end
    implementations for
    Stdin
    and
    Fileare
    now specialized to use uninitalized buffers for increased
    performance.

  • Lifetime parameters of foreign functions are now resolved
    properly.

Reusing the implementation

  • Code reuse is one of the greatest advantages that object-oriented
    programming languages provide.
  • You can also place an object of that class inside a new class. We
    call this “creating a member object.” this concept is called
    composition.
  • You can also change the member objects at run time, to dynamically
    change the behavior of your program.
  • You should first look to composition when creating new classes,
    since it is simpler and more flexible.

Misc

  • Rust can now, with some coercion, produce programs that run on
    Windows XP, though XP
    is not considered a supported platform.

  • Porting Rust on Windows from the GNU toolchain to MSVC continues
    (1,
    2,
    3,
    4). It is still not
    recommended for use in 1.3, though should be fully-functional in the
    64-bit 1.4
    beta.

  • On Fedora-based systems installation will properly configure the
    dynamic
    linker.

  • The compiler gained many new extended error descriptions, which can
    be accessed with the --explain flag.

  • The dropck pass, which checks that destructors can’t access
    destroyed values, has been
    rewritten. This fixes
    some soundness holes, and as such will cause some
    previously-compiling code to no longer build.

  • rustc now uses LLVM to write archive files where
    possible. Eventually
    this will eliminate the compiler’s dependency on the ar utility.

  • Rust has preliminary support for i686
    FreeBSD
    (it has long supported FreeBSD on x86_64).

  • The unused_mut,
    unconditional_recursion,improper_ctypes,
    and
    negate_unsigned
    lints are more strict.

  • If landing pads are disabled (with -Z no-landing-pads),
    panic!will kill the process instead of
    leaking.

更多内容可查看:Rust-1.3。

Rust 是 Mozilla 的一个新的编程语言,由web语言的领军人物Brendan
Eich(js之父),Dave Herman以及Mozilla公司的Graydon Hoare 合力开发。

文章转载自:开源中国社区 []    

Inheritance

  • Two types can have characteristics and behaviors in common, but one
    type may contain more characteristics than another and may also
    handle more messages.
  • This new type contains not only all the members of the existing type
    (although the private ones are hidden away and
    inaccessible), but more importantly it duplicates the interface of
    the base class.
  • Since we know the type of a class by the messages we can send to it,
    this means that the derived class is the same type as the base
    class.
  • This type equivalence via inheritance is one of the fundamental
    gateways in understanding the meaning of object-oriented
    programming.
  • You have two ways to differentiate your new derived class from the
    original base class: Simply add brand new methods to the derived
    class Or to change the behavior of an existing base-class method.

Is-a vs. is-like-a relationships

  • A test for inheritance is to determine whether you can state the
    is-a relationship about the classes and have it make sense.
  • The new type can still be substituted for the base type, but the
    substitution isn’t perfect because your new methods are not
    accessible from the base type.
  • The interface of the new object has been extended, and the existing
    system doesn’t know about anything except the original interface.

Interchangeable objects with polymorphism

  • When dealing with type hierarchies, you often want to treat an
    object not as the specific type that it is, but instead as its base
    type. This allows you to write code that doesn’t depend on specific
    types.
  • This ability to easily extend a design by deriving new subtypes is
    one of the essential ways to encapsulate change.
  • If a method is going to tell a generic shape to draw itself, the
    compiler cannot know at compile time precisely what piece of code
    will be executed.
  • When the message is sent, the programmer doesn’t want to know what
    piece of code will be executed.
  • The function call generated by a non-OOP compiler causes what is
    called early binding, It means the compiler generates a call to a
    specific function name, and the runtime system resolves this call to
    the absolute address of the code to be executed.
  • Object-oriented languages use the concept of late binding. When you
    send a message to an object, the code being called isn’t determined
    until run time.
  • The compiler does ensure that the method exists and performs type
    checking on the arguments and return value, but it doesn’t know the
    exact code to execute.
  • In Java, dynamic binding is the default behavior and you don’t need
    to remember to add any extra keywords in order to get polymorphism.
  • We call this process of treating a derived type as though it were
    its base type upcasting.

The singly rooted hierarchy

  • Whether all classes should ultimately be inherited from a single
    base class?
  • It turns out that the benefits of the singly rooted hierarchy are
    many.
  • A singly rooted hierarchy makes it much easier to implement a
    garbage collector
网站地图xml地图