Skip to content

Commit

Permalink
use OrderedTable instead of OrderedTableRef for mimedb (nim-lang#19522)
Browse files Browse the repository at this point in the history
* use OrderedTable instead of OrderedTableRef for mimedb

Signed-off-by: David Krause <enthus1ast@users.noreply.github.com>

* added changelog entry for mimedb change

Signed-off-by: David Krause <enthus1ast@users.noreply.github.com>
  • Loading branch information
enthus1ast authored and PMunch committed Mar 28, 2022
1 parent 3c51ce5 commit 0503a5e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ becomes an alias for `addr`.

- Added `std/oserrors` for OS error reporting. Added `std/envvars` for environment variables handling.

- Changed mimedb to use an `OrderedTable` instead of `OrderedTableRef`, to use it in a const.

## Language changes

- Pragma macros on type definitions can now return `nnkTypeSection` nodes as well as `nnkTypeDef`,
Expand Down
4 changes: 2 additions & 2 deletions lib/pure/mimetypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ from strutils import startsWith, toLowerAscii, strip

type
MimeDB* = object
mimes: OrderedTableRef[string, string]
mimes: OrderedTable[string, string]

const mimes* = {
"123": "application/vnd.lotus-1-2-3",
Expand Down Expand Up @@ -1904,7 +1904,7 @@ func newMimetypes*(): MimeDB =
## Creates a new Mimetypes database. The database will contain the most
## common mimetypes.
{.cast(noSideEffect).}:
result.mimes = mimes.newOrderedTable()
result.mimes = mimes.toOrderedTable()

func getMimetype*(mimedb: MimeDB, ext: string, default = "text/plain"): string =
## Gets mimetype which corresponds to `ext`. Returns `default` if `ext`
Expand Down
2 changes: 2 additions & 0 deletions tests/stdlib/tmimetypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ template main() =
var m = newMimetypes()
doAssert m.getMimetype("mp4") == "video/mp4"
doAssert m.getExt("application/json") == "json"
m.register("foo", "baa")
doAssert m.getMimetype("foo") == "baa"
# see also `runnableExamples`.
# xxx we should have a way to avoid duplicating code between runnableExamples and tests

Expand Down

0 comments on commit 0503a5e

Please sign in to comment.