traits

Does Rust have Collection traits?

﹥>﹥吖頭↗ 提交于 2019-12-04 23:28:29
I'd like to write a library that's a thin wrapper around some of the functionality in BTreeMap . I'd prefer not to tightly couple it to that particular data structure though. Strictly speaking, I only need a subset of its functionality, something along the lines of the NavigableMap interface in Java. I was hoping to find an analogous trait I could use. I seem to recall that at some point there were traits like Map and MutableMap in the standard library, but they seem to be absent now. Is there a crate that defines these? Or will they eventually be re-added to std? No, right now there's only

Semantics of abstract traits in Scala

自古美人都是妖i 提交于 2019-12-04 22:57:31
I am wondering what the semantics of using the abstract keyword in combination with a trait is. If the trait does not define any abstract methods, the abstract keyword does not prevent me from creating an instance: scala> abstract trait T defined trait T scala> new T{} res0: java.lang.Object with T = $anon$1@12cd927d On the other hand, if the trait does define an abstract method, I cannot create an instance (without implementing this method of course) no matter if the abstract keyword is present or not: scala> abstract trait T { def foo : Unit } defined trait T scala> new T{} <console>:9:

How to initialize the value from trait in subtype?

守給你的承諾、 提交于 2019-12-04 21:10:55
问题 If I write : trait T { val t = 3 val u = 1::t::Nil } class U extends T { override val t = 2 } (new U).u it shows this. List(1, 0) How should I change the above code to make it display the following: List(1, 2) i.e. override val t sets the value of t for u in the trait T ? 回答1: One way to do this is to delay evaluation of u by using def or lazy val as follows: trait T { def t = 3 def u = 1::t::Nil } class U extends T { override def t = 2 } (new U).u or trait T { val t = 3 lazy val u = 1::t:

What does the exclamation point mean in a trait implementation?

二次信任 提交于 2019-12-04 17:49:38
问题 I found in the library reference for std::rc::Rc this trait implementation impl<T> !Send for Rc<T> where T: ?Sized, What does the exclamation point in front of Send mean? I consulted both The Rust Programming Language¹ book and The Rust Reference², but didn't find an explanation. Please give a reference in your answer. ¹ especially the [section 3.19 Traits ² and sections 5.1 Traits and 5.1 Implementations 回答1: It's a negative trait implementation for the Send trait as described in RFC 19. As

Codeigniter 3: How to use composer packages? (Twilio SDK)

末鹿安然 提交于 2019-12-04 16:52:29
What I did so far: I am pretty familiar with CI, but new to composer and the twilio SDK. Reading some tutorials and docs I managed to install composer and the twilio package. However the /vendor folder is parallel to my CI installation: /var/www/html/ - application - system - vendor I have therefore edited the config.php setting the path like this: $config['composer_autoload'] = '/var/www/html/vendor/autoload.php'; In my controller tried to use the SDK as documented in the Twilio SDK: <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Test extends CI_Controller { use

Scala's MapLike, ListLike, SeqLike, etc how does each compare to Map, List, Seq?

醉酒当歌 提交于 2019-12-04 15:53:08
问题 Could someone please help me understand Scala's various "Like" traits in the collection API. I've been reading over and trying to compare each without luck. I think I can see that Map for example, extends MapLike - adding 2 concrete methods. But this begs the question of why do this at all? Why not just have 1 Map trait in the Collections API instead of Map and MapLike? Thank you! 回答1: The best source for these details is Martin Odersky and Lex Spoon's "What's New in Scala 2.8: The

How are Scala's traits not really traits?

别等时光非礼了梦想. 提交于 2019-12-04 12:03:54
问题 Someone recently told me that Scala's traits aren't "true" traits, and that they were really just mixins. Unfortunately, I didn't get the opportunity to ask him why. Does anyone have an idea what he meant? Edit: As a definition of "traits," I have been referring to Nathanael Schärli’s dissertation and concept paper introducing traits. One key feature that seems to be missing from most mixin and/or multiple inheritance implementations is the ability to rename methods when you import them to

SFINAE issue in creating an “is_iterable” trait - is this a gcc bug?

≯℡__Kan透↙ 提交于 2019-12-04 09:29:09
The following code attempts (without using c++11) to create a trait for identifying whether a type is iterable in STL fashion : #include <iostream> #include <vector> template<typename C> struct IsIterable { typedef char true_type; typedef long false_type; template<class T> static true_type is_beg_iterable( typename T::const_iterator = C().begin()); template<class T> static false_type is_beg_iterable(...); enum { value = sizeof(is_beg_iterable<C>()) == sizeof(true_type) }; }; int main() { std::cout << IsIterable<std::vector<int>>::value << std::endl; } there's also an is_end_iterable method,

Mixin or Trait implementation in AS3?

早过忘川 提交于 2019-12-04 07:10:53
I'm looking for ideas on how to implement a Mixin/Trait style system in AS3. I want to be able to compose a number of classes together into a single object. Of course this is not a language level feature of AS3, but I'm hoping that there is maybe some way to do this using prototype based techniques or maybe some bytecode hacking that I believe AsMock uses to implement it's functionality. An existing Java example is Qi4J where the user define interfaces that the Qi4j framework implements based on metadata tags and coding by convention. Has anyone any ideas on how to get the Mixin/Trait concept

How can I create hashable trait objects / trait objects with generic method parameters?

这一生的挚爱 提交于 2019-12-04 07:02:47
I have some structs that implement both Hash and MyTrait . I'm using them as &MyTrait trait objects. Now I want &MyTrait to also implement Hash . I've tried a few things: Naively, trait MyTrait: Hash {} : the trait `MyTrait` cannot be made into an object Then I tried this: impl Hash for MyTrait { fn hash<H: Hasher>(&self, hasher: &mut H) { // ... } } but I need to delegate to the hash method of the concrete type of self , I think. So the naive next step is to put this on MyTrait : fn my_hash<H: Hasher>(&self, hasher: &mut H); which brings me right back to the first point. I read something