2013-01-20 12:46:06 -06:00
|
|
|
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-06-06 18:33:44 -05:00
|
|
|
//! Traits for generic collections
|
2013-01-23 11:21:58 -06:00
|
|
|
|
2013-05-28 16:35:52 -05:00
|
|
|
/// A trait to represent the abstract idea of a container. The only concrete
|
|
|
|
/// knowledge known is the number of elements contained within.
|
2014-05-19 13:32:09 -05:00
|
|
|
pub trait Collection {
|
2013-01-21 20:59:19 -06:00
|
|
|
/// Return the number of elements in the container
|
2013-06-15 01:20:06 -05:00
|
|
|
fn len(&self) -> uint;
|
2013-01-21 20:59:19 -06:00
|
|
|
|
|
|
|
/// Return true if the container contains no elements
|
2013-07-25 03:02:08 -05:00
|
|
|
#[inline]
|
|
|
|
fn is_empty(&self) -> bool {
|
|
|
|
self.len() == 0
|
|
|
|
}
|
2013-01-21 20:59:19 -06:00
|
|
|
}
|