Reidar Sollid's Blog

Just another site

Archive for April 2013

Import Rust file to RustyCage

leave a comment »

The import Rust file wizard will copy a file from your file system into your current workspace in Eclipse. So from the “File” menu chose Import.

Screenshot from 2013-04-23 23:46:52

Then from the Import wizard you have the Rust category and in there you can chose Rust file. The Import Rust Project is not implemented as for now. Sorry.

Screenshot from 2013-04-23 23:48:13

Then press the “next>” button and chose the “src” folder.

Screenshot from 2013-04-23 23:48:38

Then press the “browse” button or enter the path to your file.Screenshot from 2013-04-23 23:49:30

Screenshot from 2013-04-23 23:49:51

Then press the “Finish” button.

Screenshot from 2013-04-23 23:50:16

And viola, your Rust file is imported/copied into your workspace and project.

Written by reidarsollid

April 23, 2013 at 10:00 pm

Posted in Rust, software

String split method to return a tuple

leave a comment »

So basically I thought this would be a cool thing to do in Scala, returning a tuple from the String split method.

val (str1,str2) = text.split(":")

But it doesn’t, String split returns an array.

val array:Array[String] = text.split(":")

So what can we do, so I was thinking “I can solve this with implicit conversion can’t I?”. Of course I can, so here is what I did. First I created a class with a function splitToTuple returning a tuple from the split. I wanted to split on io::println in Rust so that I could get content assist for the editor, if io:: is pressed I wanted the tuple to be returned as (“io”,””) to return all the functions in the io package.

class StringSplitToTuple(s: String) {
  def splitToTuple(regex: String): (String, String) = {
    s.split(regex) match {
      case Array(str1, str2) = (str1, str2)
      case Array(str1) = (str1, "")
      case _ = error("too many colons")

Then I needed an object to hold the implicit conversion.

object SplitToTuple {
  implicit def splitToTuple(regex: String) = new StringSplitToTuple(regex)

And viola, now I can get a tuple from Strings split method.

import SplitToTuple._
object Main extends App {
  val (str1, str2) =  "io::println".splitToTuple("::")

Written by reidarsollid

April 23, 2013 at 9:31 pm

Posted in Scala, software