social.gl-como.it

Cerca

Elementi taggati con: programming

Functional #Programming in #Erlang

Functional Programming in Erlang - Free online course

Learn the theory and practice of functional programming in Erlang, through practical exercises and suggested projects.
 
Bruce Schneier: The US government is coming for YOUR code, techies
Software flaws that may once have been capable of crashing applications have the potential to crash cars, planes, medical devices, appliances, and other connected infrastructure. As a result, Schneier contends, the restrictions and regulations that attempt to defend against real world risks will be placed on the tech world.

"What we're going to see is increased government involvement," Schneier said. "Because that's what happens in the world of dangerous things."

https://www.theregister.co.uk/2017/02/14/the_government_is_coming_for_your_code/

I don't think this is just about the US government, but US media seems to forget there is a world outside. I'm not sure it's necessarily a bad thing either, but as Schneier points out it all depends on how informed the agencies or institutions that constitute this involvement will be.

#programming #society

Bruce Schneier: The US government is coming for YOUR code, techies

Open source has won, but victory may be fleeting
 
Pathfinder, a Fast GPU-based Font Rasterizer in Rust

A very nice article explaining a lot of insights into the technicalities around font rendering. The post itself isn't really about rust, but shows you can do some really nice things in this language.

https://pcwalton.github.io/blog/2017/02/14/pathfinder/

#programming #fonts #rendering #rust

Pathfinder, a fast GPU-based font rasterizer in Rust - pcwalton

Ever since some initial discussions with Raph Levien (author of font-rs) at RustConf last
September, I’ve been thinking about ways to improve …
 
#Django #Web #Framework ( #Python ) tutorial https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django #dev #programming

Django Web Framework (Python)

Django is an extremely popular and fully featured server-side web framework, written in Python. The module shows you why Django is one of the most popular web server frameworks, how to set up a development environment, and how to get started with using it to create your own web applications.
 
Hello Diaspora! I am #newhere
First: English is not my native language and writing or speaking in it is quite hard for me yet (I've got far more experience in reading or listening rather than writing or speaking). I choose English cause of English-speaking community is (most probably) larger and includes majority of somewhat educated Russian-speaking community anyway, while diaspora is not yet very popular social network yet, and what probably more important some English practice makes interaction with social network less useless time wasting. I have a hope to be corrected if I do something too horrible to the language.

Second: It's hard for me to write introduction cause apparently it's hard to choose what things I'm interested in. I wonder how other choose just few tags. It doesn't feel reasonable to try to list everything I have ever been interested in, yet I'm not sure if it better choose only few things I consider important, or is it more sensible to focus on things I already have seen being mentioned by someone? It seems I came to piling up most of things I can remember to be involved lately and some I was not.
* I guess i can start from mentioning my profession which is about #programming , more precisely I use С# for some dubious objectives but interested mostly in anything related to algorithms and machine learning.
* I'm also interested in #unicycle, and that's how I usually go to work.
* I'm interested in #rationality including #lesswrong
* Since childhood I often wonder why so many people put up with short lifespan and I'm interested in increasing life #longevity.
* I'm a bit tired from anything related to #politics, yet I tend to think there should be a way how relatively sane people can and should (at least partially) fix current state of the system.
* I'm mostly #agnostic yet I can sympathize to some religions like #discordianism #kopimism #buddhism some sorts of #pagan[ism].
* Sometimes I dabble in #magic and partially related stuff like #out-of-body expirience and simple #lucid-dreaming #meditation #chaos-magick and some other even more questionable stuff.
* I like to use unusual writing systems starting from #tengwar
* I can add to list some purely entertaining things like #anime, and #MLP. I also read some #books while my favorite authors use Russian language and their works are practically not translated, and two last English language things which impressed me lately are fanfiction (Fallout: Equestria and #HPMOR)

I use the same nickname (Lurr = Лурр) for a quite a long time.
My profiles in other networks:
vk (RU) (substitute wolf for ulf to get older profile)
livejournal (RU)
stackoverflow
deviantart
furnation (RU) (not active for a long time)
facebook (quite empty)
MyAnimeList

https://vk.com/wolflurr
 
#Go is Not Good https://github.com/ksimka/go-is-not-good #golang #dev #programming

ksimka/go-is-not-good

go-is-not-good - A curated list of articles complaining that go (golang) isn't good enough
 
Hello, I'm #newhere! I'm interested in many things, including but not limited to: #programming, #rust, #gamedev, #riscv, #arduino, #decentralization, etc.

Diaspora is looks like it will be awesome.
 
Hello, I'm #newhere! I'm interested in many things, including but not limited to: #programming, #rust, #gamedev, #riscv, #arduino, #decentralization, etc.

Diaspora is looks like it will be awesome.
 
Hello, I'm #newhere! I'm interested in many things, including but not limited to: #programming, #rust, #gamedev, #riscv, #arduino, #decentralization, etc.

Diaspora is looks like it will be awesome.
 
Hello Diaspora! I am #newhere
First: English is not my native language and writing or speaking in it is quite hard for me yet (I've got far more experience in reading or listening rather than writing or speaking). I choose English cause of English-speaking community is (most probably) larger and includes majority of somewhat educated Russian-speaking community anyway, while diaspora is not yet very popular social network yet, and what probably more important some English practice makes interaction with social network less useless time wasting. I have a hope to be corrected if I do something too horrible to the language.

Second: It's hard for me to write introduction cause apparently it's hard to choose what things I'm interested in. I wonder how other choose just few tags. It doesn't feel reasonable to try to list everything I have ever been interested in, yet I'm not sure if it better choose only few things I consider important, or is it more sensible to focus on things I already have seen being mentioned by someone? It seems I came to piling up most of things I can remember to be involved lately and some I was not.
* I guess i can start from mentioning my profession which is about #programming , more precisely I use С# for some dubious objectives but interested mostly in anything related to algorithms and machine learning.
* I'm also interested in #unicycle, and that's how I usually go to work.
* I'm interested in #rationality including #lesswrong
* Since childhood I often wonder why so many people put up with short lifespan and I'm interested in increasing life #longevity.
* I'm a bit tired from anything related to #politics, yet I tend to think there should be a way how relatively sane people can and should (at least partially) fix current state of the system.
* I'm mostly #agnostic yet I can sympathize to some religions like #discordianism #kopimism #buddhism some sorts of #pagan[ism].
* Sometimes I dabble in #magic and partially related stuff like #out-of-body expirience and simple #lucid-dreaming #meditation #chaos-magick and some other even more questionable stuff.
* I like to use unusual writing systems starting from #tengwar
* I can add to list some purely entertaining things like #anime, and #MLP. I also read some #books while my favorite authors use Russian language and their works are practically not translated, and two last English language things which impressed me lately are fanfiction (Fallout: Equestria and #HPMOR)

I use the same nickname (Lurr = Лурр) for a quite a long time.
My profiles in other networks:
vk (RU) (substitute wolf for ulf to get older profile)
livejournal (RU)
stackoverflow
deviantart
furnation (RU) (not active for a long time)
facebook (quite empty)
MyAnimeList

https://vk.com/wolflurr
 
Stop Filing Bugs, File a Container! http://blog.runkit.com/2017/02/01/stop-filing-bugs-file-a-container.html #dev #programming

Stop Filing Bugs, File a Container!

RunKit notebooks are a great way to file bugs on GitHub. Since RunKit automatically packages your code with its entire environment in a Docker container, anyone can clone your bug and start investi...
 
Piet is a programming language in which programs look like abstract paintings. The language is named after Piet Mondrian, who pioneered the field of geometric abstract art.

Immagine/foto

http://www.dangermouse.net/esoteric/piet.html

#programming #programminglanguage #piet #art #abstract

DM's Esoteric Programming Languages - Piet

DM's Esoteric Programming Languages - Piet
 
Piet is a programming language in which programs look like abstract paintings. The language is named after Piet Mondrian, who pioneered the field of geometric abstract art.

Immagine/foto

http://www.dangermouse.net/esoteric/piet.html

#programming #programminglanguage #piet #art #abstract

DM's Esoteric Programming Languages - Piet

DM's Esoteric Programming Languages - Piet
 
#Pycycle: Find and fix circular imports in #python projects https://github.com/bndr/pycycle #dev #programming

bndr/pycycle

pycycle - Tool for pinpointing circular imports in Python. Find circle imports in any project
 
git-recall - Simple and handy tool to easily recall what you've done with #Git https://github.com/Fakerr/git-recall #dcvs #dev #programming

Fakerr/git-recall

git-recall - Simple and handy tool to easily recall what you've done
 
Top ten pull request review mistakes https://blog.scottnonnenberg.com/top-ten-pull-request-review-mistakes/ #dev #programming

Top ten pull request review mistakes

I’ve worked on a whole lot of GitHub-hosted projects, whether personal, open-source, or on contract. Sometimes using the public GitHub, and other times GitHub Enterprise. But one thing is the same: it’s pretty easy to submit a pull request, but it’s really hard to review a pull request well.
Without further ado, the top ten pull request review mistakes and some ideas on how to do better!
 
Making the move from #Scala to #Go, and why we’re not going back https://movio.co/blog/migrate-Scala-to-Go/ #dev #programming

Making the move from Scala to Go, and why we're not going back

Here’s the story of why we chose to migrate from Scala to Go, and gradually rewrote part of our Scala codebase to Go.
 
#Racket v6.8 released http://blog.racket-lang.org/2017/01/racket-v6-8.html #dev #programming

Racket v6.8

_posted by Vincent St-Amour_ Racket version 6.8 is now available from http://racket-lang.org/ Racket sports a new logo, courtesy of Matthew Butterick. MacBook Pro laptops with touch bars are supported. Support for FreeBSD on PowerPC. ...
 
Announcing #pipenv https://www.kennethreitz.org/essays/announcing-pipenv #python #dev #programming

Announcing Pipenv!

I wrote a new tool this weekend, called pipenv. Check it out on GitHub!

Pipenv in action.

Pipenv is an experimental project that aims to bring the best of all
packaging worlds to the Python world. It harnesses Pipfile, pip, and
virtualenv into one single toolchain. It features very pretty terminal
colors.

It automatically creates and manages a virtualenv for your projects, as
well as adds/removes packages from your Pipfile as you install/uninstall
packages. The lock command generates a lockfile (Pipfile.lock).

☤ Features
* Automatically finds your project home, recursively, by looking for a
Pipfile.
* Automatically generates a Pipfile, if one doesn't exist.
* Automatically generates a Pipfile.lock, if one doesn't exist.
* Automatically creates a virtualenv in a standard location
(project/.venv).
* Automatically adds packages to a Pipfile when they are installed.
* Automatically removes packages from a Pipfile when they are
un-installed.
* Also automatically updates pip.

The main commands are install, uninstall, and lock, which generates a
Pipfile.lock. These are intended to replace $ pip install usage, as well as
manual virtualenv management.

☤ Basic Concepts
* A virtualenv will automatically be created, when one doesn't exist.
* When no parameters are passed to install, all packages specified will
be installed.
* When no parameters are passed to uninstall, all packages will be
uninstalled.
* To initialize a Python 3 virtual environment, run $ pipenv --three
 first.
* To initialize a Python 2 virtual environment, run $ pipenv --two
 first.
* Otherwise, whatever $ which python will be the default.
☤ Other Commands
* shell will spawn a shell with the virtualenv activated.
* run will run a given command from the virtualenv, with any arguments
forwarded (e.g. $ pipenv run python).
* check asserts that PEP 508 requirements are being met by the current
environment.
☤ Usage

$ pipenv
Usage: pipenv [OPTIONS]COMMAND [ARGS]...

Options:
--where Output project home information.
--bare Minimal output.
--three / --two Use Python 3/2 when creating virtualenv.
--version Show the version and exit.
--help Show this message and exit.

Commands:
check Checks PEP 508 markers provided in Pipfile.
install Installs a provided package and adds it to...
lock Generates Pipfile.lock.
run Spans a command installed into the...
shell Spans a shell within the virtualenv.
uninstall Un-installs a provided package and removes it...
update Updates pip to latest version, uninstalls all...


$ pipenv --where
Pipfile found at /Users/kennethreitz/repos/kr/pip2/test/Pipfile. Considering this to be the project home.


$ pipenv install
Creating a virtualenv for this project...
...
No package provided, installing all dependencies.
Virtualenv location: /Users/kennethreitz/repos/kr/pip2/test/.venv
Installing dependencies from Pipfile.lock...
...

To activate this project's virtualenv, run the following:
$ pipenv shell


$ pipenv install pytest --dev
Installing pytest...
...
Adding pytest to Pipfile's [dev-packages]...


$ pipenv lock
Assuring all dependencies from Pipfile are installed...
Locking [dev-packages] dependencies...
Locking [packages]dependencies...
Note: your project now has only default [packages]installed.
To install [dev-packages], run: $ pipenv init --dev



$ pipenv install --dev
Pipfile found at /Users/kennethreitz/repos/kr/pip2/test/Pipfile. Considering this to be the project home.
Pipfile.lock out of date, updating...
Assuring all dependencies from Pipfile are installed...
Locking [dev-packages] dependencies...
Locking [packages]dependencies...
Note: your project now has only default [packages]installed.
To install [dev-packages], run: $ pipenv install --dev
Installing dependencies from Pipfile.lock...
...


$ pipenv uninstall
No package provided, un-installing all dependencies.
Found 25 installed package(s), purging...
...
Environment now purged and fresh!


$ pipenv shell
Spawning virtualenv shell (/bin/zsh).
(test)$

 ☤ Installation

$ pip install pipenv

✨🍰✨
 
Scaling #Python is on its way https://julien.danjou.info/blog/2017/announcing-scaling-python #dev #programming #book

Scaling Python is on its way

My day-to-day activities are still evolving around the Python programming language, as I continue working on the OpenStack project as part of my job at Red Hat. OpenStack is still the biggest Python …
 
Immagine/foto
Haha, this is why you don't put stuff from url params directly on a page!

#programming #webdev #inputvalidation #oracle #fail
 
Using #Git Hunks https://www.bignerdranch.com/blog/using-git-hunks/ #dev #programming

Using Git Hunks

As a developer, I always try to follow the “Boy Scout Principle” when it comes to the code I’m working with. Simply put:
 
Hi Diaspora*! Just signed up and getting the hang of this site. A bit about me, Huge #Nerd, #Linux #Cypherpunk #Crypto #Hacker but in the pre-1984 sense of the word. #OpenSource #Programming and #Webdesign. #Mathematics.

Any friends from #Galaxy2 ?
 
3 ways of testing #Django views https://yoongkang.com/blog/3-ways-of-testing-django-views/ #web #programming

3 ways of testing Django views

I tried 3 different ways of testing a Django view. These are my thoughts.
 
 
WOW.
For the same reason, "6" == " 6", "4.2" == "4.20", and "133" == "0133". But note that 133 != 0133, because 0133 is octal. But "0x10" == "16" and "1e3" == "1000"!

https://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/

#php #programming

PHP: a fractal of bad design

(This article has been translated into Spanish (PDF, with some additions) by Jorge Amado Soria Ramirez — thanks!) Preface I’m cranky. I complain about a lot of things. There’s a lot in the world of technology I don’t like, and that’s really to be expected—programming is a hilariously young discipline, and none of us have the slightest clue what we’re doing. Combine with Sturgeon’s Law, and I have a lifetime’s worth of stuff to gripe about. This is not the same. PHP is not merely awkward to use, or ill-suited for what I want, or suboptimal, or against my religion. I can tell you all manner of good things about languages I avoid, and all manner of bad things about languages I enjoy. Go on, ask! It makes for interesting conversation. PHP is the lone exception. Virtually every feature in PHP is broken somehow. The language, the framework, the ecosystem, are all just bad. And I can’t even point out any single damning thing, because the damage is so systemic. Every time I try to compile a list of PHP gripes, I get stuck in this depth-first search discovering more and more appalling trivia. (Hence, fractal.) PHP is an embarrassment, a blight upon my craft. It’s so broken, but so lauded by every empowered amateur who’s yet to learn anything else, as to be maddening. It has paltry few redeeming qualities and I would prefer to forget it exists at all. But I’ve got to get this out of my system. So here goes, one last try. An analogy I just blurted this out to Mel to explain my frustration and she insisted that I reproduce it here. I can’t even say what’s wrong with PHP, because— okay. Imagine you have uh, a toolbox. A set of tools. Looks okay, standard stuff in there. You pull out a screwdriver, and you see it’s one of those weird tri-headed things. Okay, well, that’s not very useful to you, but you guess it comes in handy sometimes. You pull out the hammer, but to your dismay, it has the claw part on both sides. Still serviceable though, I mean, you can hit nails with the middle of the head holding it sideways. You pull out the pliers, but they don’t have those serrated surfaces; it’s flat and smooth. That’s less useful, but it still turns bolts well enough, so whatever. And on you go. Everything in the box is kind of weird and quirky, but maybe not enough to make it completely worthless. And there’s no clear problem with the set as a whole; it still has all the tools. Now imagine you meet millions of carpenters using this toolbox who tell you “well hey what’s the problem with these tools? They’re all I’ve ever used and they work fine!” And the carpenters show you the houses they’ve built, where every room is a pentagon and the roof is upside-down. And you knock on the front door and it just collapses inwards and they all yell at you for breaking their door. That’s what’s wrong with PHP.
 
 
#Voluptuous ,#Python data validation library https://github.com/alecthomas/voluptuous #dev #programming

alecthomas/voluptuous

voluptuous - Voluptuous, despite the name, is a Python data validation library.
 
#Python 3.6 is packed with goodness http://www.infoworld.com/article/3149782/application-development/python-36-is-packed-with-goodness.html #dev #programming

Python 3.6 is packed with goodness

More async support, more type-hinting power, more speed, and more efficient memory usage top a long list of useful additions to Python
 
Simulating exceptions in Rust with IIFE

This is a very elegant technique for streamlining error handling in Rust.

#programming #rust

Simulating exceptions in Rust with IIFE

While many languages use exceptions for handling errors, Rust prefers a slightly different, yet very classical approach: return values. Now, they aren’t exactly the same thing as in C, where the error is indicated by a special value within the same return type. In Rust, the Result enum can neatly separate the two, in similar vein to how ad-hoc tuples in Go do1. But unlike Go, Rust also offers additional facilities for error propagation, including the try! macro and the recently stabilized ? operator. And finally, the Result wrappings can be straightforwardly unpacked, possibly by defaulting to a known safe value. Some conveniences of exceptions may be hard to pass up, though. The try-catch construct is evidently one of them, and Rust might eventually get it in one form or another. Before that happens, however, there is a trick that can often work as an acceptable substitute. Many lets Here’s an example where it can be very useful. Have a look at the following function. Its purpose is to retrieve a GitHub login of a user who owns a specific gist — a small sample of code posted to the gists.github.com website2. Let’s assume we have already talked to GitHub API and received the following JSON response from its relevant endpoint: { "id": "12345678", "owner": { "login": "Octocat", ... } ... } Parsing it is easy: we can do it with the rustc_serialize crate, among other options. What proves a little more involved is to dig through the JSON tree in order to reach the interesting value: use rustc_serialize::json::Json; /// Retrieve the gist owner from a JSON received from /// the /gists/$ID endpoint of the GitHub API. /// /// If the gist is anonymous, "anonymous" is returned. fn gist_owner_from_info(info: &Json) -> String { if let Some(info) = info.as_object() { if let Some(owner) = info.get("owner").and_then(|o| o.as_object()) { if let Some(result) = owner.get("login").and_then(|l| l.as_string()) { return result.to_owned(); } } } "anonymous".into() } Whew! I guess we’re lucky we don’t need to go too deep into that JSON. The code is clearly exhibiting a rightward slant, which some people refer to as the “arrow code”, Unsurprisingly, it is generally considered bad for readability. There are few other ways of writing this, of course, including a style reminiscent of JavaScript promises — that is, relying completely on the and_then method. Neither seem very satisfying, though, especially if you compare it with something like this: try: return str(info["owner"]["login"]) except (KeyError, TypeError): return "anonymous" Yes, exceptions are quite useful sometimes. So, how can we get something like this in Rust? JavaScript for the rescue Succor comes from an unexpected direction. To emulate exceptions — specifically, the try-catch exception blocks — we can utilize a technique that is most popular in… JavaScript. At least until recently, JavaScript did not have a block local scope. Since every variable declaration within a function is hoisted to the top of that function, it essentially makes function scope the only usable one (besides global, of course). As a result, a variety of JavaScript idioms rely on introducing “superfluous” functions, solely for the purpose of creating a nested scope. Many times, those functions are neither named nor stored in any variable; rather, they are immediately invoked. This is what is commonly understood as Immediately Invoked Function Expression, or IIFE for short. An oft-cited example involves an IIFE which itself returns another function: for (var i = 0; i < 10; ++i) { var $para = $("p#" + i); // <p id="0">, <p id="1">, etc. var clickHandler = (function(i) { // IIFE! return function() { alert("Clicked element no. " + (i + 1)); }; })(i); $para.on('click', clickHandler); } The function expression is necessary here, because it allows to control what exactly goes into the closure of the inner function. If the clickHandlers were assigned the function() { alert(...) } expression directly, they would all close over the same loop counter variable. All would then display the exact same message. We don’t need to employ those workarounds in Rust. Thanks to local scoping, a simple pair of { bracers } would work exactly the same. You can imagine a direct rewrite of the above example, though, where an anonymous closure is used to similar effect: // WARNING: Not idiomatic! (Also not a real DOM library). for i in (0..10) { let para = dom.find_element_by_id("p", i.to_string()).unwrap(); let click_handler = |i| { |_: Event| { dom.exec_js(&format!( "alert('Clicked element no. #{}');", i + 1)); } }(i); para.add_event_listener(Event::Click, click_handler) } In other words, Rust supports IIFEs just fine. Just put a function on it Okay, this is quite amusing and probably pretty neat. But does it help us with the error handling story exactly?… Let’s take another stab at rewriting the gist_owner_from_info routine. This time, we’ll extract the meaty part into a separate function. We will also take advantage of one trivial, but very useful try_opt crate which is essentially an equivalent of the try! macro for Options: # [macro_use]extern crate try_opt; fn gist_owner_from_info(info: &Json) -> String { gist_owner_from_info_internal(info).unwrap_or("anonymous".into()) } fn gist_owner_from_info_internal(info: &Json) -> Option<String> { let info = try_opt!(info.as_object()); let owner = try_opt!(info.get("owner").and_then(|o| o.as_object())); let login = try_opt!(owner.get("login").and_then(|l| l.as_string())); Some(login.to_owned()) } Now this should be a little easier on the eyes. (And if you want, you can eschew and_then completely in favor of more try_opt!). The downside is that we now have this _internal function that’s awkwardly sticking out. We could pull it in, and turn it into an inner function, but why stop half-way? Let’s just make it an IIFE already: fn gist_owner_from_info(info: &Json) -> String { || -> Option<String> { let info = try_opt!(info.as_object()); let owner = try_opt!(info.get("owner").and_then(|o| o.as_object())); let login = try_opt!(owner.get("login").and_then(|l| l.as_string())); Some(login.to_owned()) }().unwrap_or("anonymous".into()) } Not bad, eh? The analogies with exception handling should be pretty evident, too3: The closure itself works as a try block, with closure’s body containing the “guarded” code. The unwrap family of methods (especially unwrap_or_else) dubs for a catch/except section. Sure, we do need try! (or try_opt!) macros to mark instructions that may “throw an exception”, but with the ?-based syntax it shouldn’t be too big of a deal. And when the time comes, this code will be very easy to port to a trait-based exception handling solution that’s currently in the works. Oh, and the best part? Both Rust and the underlying LLVM are very adept at inlining closures, so everything here should compile to optimal code. Bonus: a lifetime conundrum Well, almost optimal. There is one more thing left to do before we can call this a truly zero-cost abstraction. We need to stop allocating so damn much! It should be pretty obvious that the function doesn’t need to create a brand new String every time it’s called. The text is in the input Json, and we take that Json by reference already. It’s only fair we stop creating Strings and simply return a &str reference instead. In fact, this should be as easy as removing the to_owned/into calls, right? fn gist_owner_from_info(info: &Json) -> &str { || -> Option<&str> { let info = try_opt!(info.as_object()); let owner = try_opt!(info.get("owner").and_then(|o| o.as_object())); owner.get("login").and_then(|l| l.as_string())) }().unwrap_or("anonymous") } Wrong, apparently. If you present this code to the compiler, it will serve you quite a mouthful of an error, including helpful tidbits in the vein of “expected A, found A”: error[E0495]: cannot infer an appropriate lifetime for autoref due to conflicting requirements --> src/github.rs:3:34 | 3 | let info = try_opt!(info.as_object()); | ^^^^^^^^^ | note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the block at 1:45... --> src/github.rs:1:46 | 1 | fn gist_owner_from_info(info: &Json) -> &str { | ^ note: ...so that reference does not outlive borrowed content --> src/github.rs:3:29 | 3 | let info = try_opt!(info.as_object()); | ^^^^ note: but, the lifetime must be valid for the anonymous lifetime #1 defined on the block at 2:23... --> src/github.rs:2:24 | 2 | || -> Option<&str> { | ^ note: ...so that expression is assignable (expected std::option::Option<&str>, found std::option::Option<&str>) --> src/github.rs:5:9 | 5 | owner.get("login").and_then(|l| l.as_string()) | The crux of this verbiage is that the Rust compiler is unable to reconcile the lifetime of the closure’s return value, the input, and final result of the function. It shouldn’t really be trying very hard, though, for the lifetime is obvious. It’s the same as the one implicitly attached to the input &Json. Seems like in this case, we need to be a little more helpful and label it explicitly: fn gist_owner_from_info<'i>(info: &'i Json) -> &'i str { || -> Option<&'i str> { // (rest as before) Voila, this should now compile without any issues. Once again, “Keep calm and add more 'lifetimes” proves to be an effective approach ;) Technically, they aren’t called tuples there but “multiple return values“. ↩ This is something I needed to do when rewriting this Python project of mine to Rust. ↩ This is also the closest Rust can currently get to a do notation from Haskell, at least without any macro-based hacks. ↩
 
Hi Diaspora*! Just signed up and getting the hang of this site. A bit about me, Huge #Nerd, #Linux #Cypherpunk #Crypto #Hacker but in the pre-1984 sense of the word. #OpenSource #Programming and #Webdesign. #Mathematics.

Any friends from #Galaxy2 ?
 
Hi Diaspora*! Just signed up and getting the hang of this site. A bit about me, Huge #Nerd, #Linux #Cypherpunk #Crypto #Hacker but in the pre-1984 sense of the word. #OpenSource #Programming and #Webdesign. #Mathematics.

Any friends from #Galaxy2 ?
 
nuovi vecchi