{"_id":"rust-result","_rev":"296771","name":"rust-result","description":"Mimic Rust's `std::result`","dist-tags":{"latest":"1.0.0"},"maintainers":[{"name":"raynos","email":""}],"time":{"modified":"2021-06-03T18:59:05.000Z","created":"2014-10-08T20:11:40.474Z","1.0.0":"2014-12-17T11:59:49.690Z","0.1.0":"2014-10-08T20:11:40.474Z"},"users":{"ierceg":true},"author":{"name":"Maciej Małecki","email":"me@mmalecki.com"},"repository":{"type":"git","url":"git://github.com/mmalecki/rust-result.js.git"},"versions":{"1.0.0":{"name":"rust-result","version":"1.0.0","author":{"name":"Maciej Małecki","email":"me@mmalecki.com"},"description":"Mimic Rust's `std::result`","main":"index","homepage":"https://github.com/mmalecki/rust-result.js","repository":{"type":"git","url":"git://github.com/mmalecki/rust-result.js.git"},"bugs":{"url":"https://github.com/mmalecki/rust-result.js/issues"},"scripts":{"test":"node test.js","cover":"istanbul cover --print detail --report html test.js","view-cover":"istanbul report html && opn ./coverage/index.html"},"license":"MIT","devDependencies":{"istanbul":"^0.3.5","opn":"^1.0.0","tape":"^3.0.1"},"dependencies":{"individual":"^2.0.0"},"gitHead":"98a203341cfd6847ba9373bb9d1fa665eae71a72","_id":"rust-result@1.0.0","_shasum":"34c75b2e6dc39fe5875e5bdec85b5e0f91536f72","_from":".","_npmVersion":"2.1.12","_nodeVersion":"0.10.33","_npmUser":{"name":"mmalecki","email":"me@mmalecki.com"},"maintainers":[{"name":"raynos","email":""}],"dist":{"shasum":"34c75b2e6dc39fe5875e5bdec85b5e0f91536f72","size":3157,"noattachment":false,"key":"/rust-result/-/rust-result-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/rust-result/download/rust-result-1.0.0.tgz"},"directories":{},"publish_time":1418817589690,"_cnpm_publish_time":1418817589690,"_hasShrinkwrap":false},"0.1.0":{"name":"rust-result","version":"0.1.0","author":{"name":"Maciej Małecki","email":"me@mmalecki.com"},"description":"Mimic Rust's `std::result`","license":"MIT","gitHead":"8ed4b27e95e5ab2bc7d5b2d57c4b175885a6f083","_id":"rust-result@0.1.0","scripts":{},"_shasum":"905d907daf1b0d22ed0c0e15e02db9dac282837f","_from":".","_npmVersion":"2.1.1","_nodeVersion":"0.10.32","_npmUser":{"name":"mmalecki","email":"me@mmalecki.com"},"maintainers":[{"name":"raynos","email":""}],"dist":{"shasum":"905d907daf1b0d22ed0c0e15e02db9dac282837f","size":1616,"noattachment":false,"key":"/rust-result/-/rust-result-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/rust-result/download/rust-result-0.1.0.tgz"},"directories":{},"publish_time":1412799100474,"_cnpm_publish_time":1412799100474,"_hasShrinkwrap":false}},"readme":"# rust-result.js\n\nMimic Rust's [`std::result`][result].\n\n## Installation\n\n```sh\nnpm install rust-result\n```\n\n## Usage\n\n```js\nvar fs = require('fs');\nvar Result = require('./');\n\n\n// If you want async just get a promise or something.\nvar readFile = function (path, encoding) {\n  try {\n    return Result.Ok(fs.readFileSync(path, encoding))\n  }\n  catch (ex) {\n    return Result.Err(ex)\n  }\n}\n\nvar result = readFile(__filename);\nvar v, err;\n\nif (Result.isOk(result)) {\n  v = Result.Ok(result);\n  console.log('got ' + v.length + ' bytes')\n}\nelse if (Result.isErr(result)) {\n  err = Result.Err(result);\n  console.error('oops!', err.message)\n}\n\nresult = readFile(__filename + 'I do not exist')\nif (Result.isOk(result)) {\n  v = Result.Ok(result)\n  console.log('got ' + v.length + ' bytes')\n}\nelse if (Result.isErr(result)) {\n  err = Result.Err(result)\n  console.error('oops!', err.message)\n}\n\n```\n\n## Documentation\n\n```jsig\ntype OkResult<T> : {\n  v: T\n}\ntype ErrResult<E <: Error> : {\n  err: E\n}\n\nrust-result : {\n  Ok: ((T) => OkResult<T>) |\n    ((OkResult<T>) => T) |\n    ((ErrResult<E>) => void),\n  isOk: ((OkResult<T>) => true) |\n    ((ErrResult<E>) => false)\n  Err: ((E <: Error) => ErrResult<E>) |\n    ((ErrResult<E>) => E) |\n    ((OkResult<T>) => void),\n  isErr: ((ErrResult<E>) => true) |\n    ((OkResult<T>) => false)\n}\n```\n\n### `Result.Ok`\n\nThe `Result.Ok` function is overloaded to do one of two things.\n  It can create a new `Ok` instance or it can check whether\n  the argument is an instance of `Ok`\n\nIf you call `Result.Ok` with a plain value it will return an\n  instance of `Ok` that boxes your plain value.\n\nIf you call `Result.Ok` with either an `Err` or an `Ok` instance\n  then it will return `undefined` for the `Err` and return the\n  value boxed in the `Ok`\n\n### `Result.isOk`\n\nThe `Result.isOk` function just checks whether the argument\n  is an instance of `Ok`.\n\nThis predicate function returns true if you pass it an `Ok` and\n  returns false if you pass it an `Err`\n\n### `Result.Err`\n\nThe `Result.Err` function is overloaded to do one of two things.\n  It can create a new `Err` instance or it can check whether\n  the argument is an instance of `Err`\n\nIf you call `Result.Err` with a plain error it will return an\n  instance of `Err` that boxes your plain error.\n\nIf you call `Result.Err` with either an `Err` or an `Ok` instance\n  then it will return `undefined` for the `Ok` and return the\n  value err in the `Err`\n\n### `Result.isErr`\n\nThe `Result.isErr` function just checks whether the argument\n  is an instance of `Err`.\n\nThis predicate function returns true if you pass it an `Err` and\n  returns false if you pass it an `Ok`\n\n## MIT Licenced.\n\n  [result]: http://doc.rust-lang.org/std/result/\n","_attachments":{},"homepage":"https://github.com/mmalecki/rust-result.js","bugs":{"url":"https://github.com/mmalecki/rust-result.js/issues"},"license":"MIT"}